Exemple #1
0
 def get(self):
     params = self.parser.parse_args()
     sourceModelPinYinName = pinyin.get(params.get('sourceModelName'),
                                        format='strip')
     targetModelPinYinName = pinyin.get(params.get('targetModelName'),
                                        format='strip')
     os.rename('data/' + sourceModelPinYinName,
               'data/' + targetModelPinYinName)
     if os.path.exists("model/" + sourceModelPinYinName):
         os.rename('model/' + sourceModelPinYinName,
                   'model/' + targetModelPinYinName)
     return {"code": 1, "message": "ok", "data": targetModelPinYinName}
Exemple #2
0
def image_upload():
    if request.method == 'POST':
        # 通过POST方式上传图片
        image_file = request.files['file']
        filename = secure_filename(
            pinyin.get(image_file.filename, format="numerical"))

        if allowed_file(filename):
            image_entity = ImageEntity()
            image_entity.name = image_file.filename
            image_entity.type = image_file.content_type
            image_entity.data = image_file.read()
            image_entity.time = datetime.datetime.now()

            md5 = hashlib.md5()
            md5.update(
                filename +
                datetime.datetime.strftime(image_entity.time, '%Y%m%d%H%M%S'))
            image_entity.md5_name = md5.hexdigest() + '.' + filename.rsplit(
                '.', 1)[1]

            db.session.add(image_entity)
            db.session.commit()

            return redirect('/attach/' + image_entity.md5_name)
        else:
            result = ResultModel(ResultModel.FAILED_CODE, '图片格式不合法', None)
            return jsonify(vars(result))

    return render_template('upload.html')
Exemple #3
0
 def get(self):
     params = self.parser.parse_args()
     return {
         "code": 1,
         "message": "ok",
         "data": pinyin.get(params.get('data'), format='strip')
     }
Exemple #4
0
 def get(self):
     params = self.parser.parse_args()
     modelName = params.get('modelName')
     modelPinYinName = pinyin.get(modelName, format='strip')
     if os.path.exists("model/" + modelPinYinName):
         shutil.rmtree("model/" + modelPinYinName)
     if os.path.exists("data/" + modelPinYinName):
         shutil.rmtree("data/" + modelPinYinName)
     return {"code": 1, "message": "ok", "data": "ok"}
Exemple #5
0
 def get(self):
     params = self.parser.parse_args()
     tagDatas = params.get('tagDatas')
     modelName = params.get('modelName')
     modelPinYinName = pinyin.get(modelName, format='strip')
     with open("data/" + modelPinYinName + "/train.tsv",
               'a+',
               encoding="utf8") as f:
         for text in json.loads(tagDatas):
             f.write(text + '\n')
     return {"code": 1, "message": "ok", "data": "ok"}
Exemple #6
0
 def get(self):
     params = self.parser.parse_args()
     file_name = pinyin.get(params.get('modelName'), format='strip')
     data = file_page_query.page_list(file_name, int(params.get('page')),
                                      int(params.get('count')))
     return {
         "code": 1,
         "message": "ok",
         "data": {
             "data": data,
             "size": file_page_query.count_file_lines(file_name) - 1
         }
     }
Exemple #7
0
 def get(self):
     params = self.parser.parse_args()
     modelName = params.get('modelName')
     data = params.get('data')
     # data = [["有保障"],
     #         ["无风险"],
     #         ["基金过往数据并不代表未来趋势"],
     #         ["为什么"],
     #         ["周杰伦"],
     #         ]
     modelPinYinName = pinyin.get(modelName, format='strip')
     if not os.path.exists("model/" + modelPinYinName):
         return {"code": 0, "message": "model not exist", "data": ""}
     request_data = json.loads(data)
     predict_result = predict.predict_tag(modelPinYinName, request_data)
     api_result = {}
     for i in range(len(request_data)):
         api_result[request_data[i][0]] = predict_result[i]
     return {"code": 1, "message": "ok", "data": api_result}
Exemple #8
0
def jielong(cityname,list):
    returncitylist = []
    pinyinlist = []
    for i in list:
        citypinyin = pinyin.get(i, format='strip', delimiter=' ').split()
        pinyinlist.append(citypinyin)
    pinyinname = pinyinlist[list.index(cityname)]
    lastcityname =pinyinname[-1]
    run = True
    while run:
        usedlist = []
        for j in pinyinlist:
            if j not in usedlist and j[0] == lastcityname and j != pinyinname:
                usedlist.append(j)
                returncitylist.append(list[pinyinlist.index(j)])
                lastcityname = j[-1]
            else:
                run = False

    return returncitylist
Exemple #9
0
 def review_extraction(self):
     self._sync_button(doing=self.review_extraction_button)
     try:
         segments = self._info_handler.get(INFO_TAGS)
         words = frozenset(tag for articles in segments.values()
                           for article in articles.values()
                           for tag in article)
         SelectionDialog(master=self.master,
                         title="查看 抽取词汇 ({}个)".format(len(words)),
                         default_value=sorted(
                             list(words),
                             key=lambda w: pinyin.get(
                                 w, format="strip", delimiter=" ")),
                         editable=False)
     except ValueError as v:
         s = str(v)
         self.tracker.log("值错误! [error='{}']".format(s),
                          tp=TRACKER_LOG_ERROR,
                          exc_info=v,
                          prt=True)
         messagebox.showerror(parent=self.master,
                              title="值错误",
                              message="值错误!\n"
                              "请检查对应域是否填写错误!\n"
                              "\n"
                              "错误信息:\n{}".format(s))
     except Exception as e:
         s = str(e)
         self.tracker.log("未知错误! [error='{}']".format(s),
                          tp=TRACKER_LOG_ERROR,
                          exc_info=e,
                          prt=True)
         messagebox.showerror(parent=self.master,
                              title="未知错误",
                              message="未知错误!\n"
                              "请联系开发者并汇报该错误!\n"
                              "\n"
                              "错误信息:\n{}".format(s))
     finally:
         self._sync_button()
def write_excel(path, total_summary: Dict[str, Dict[str, Any]],
                detail_summary: Dict[str, Dict[str, Dict[str, int]]], sorting,
                tracker, show_detail):
    """
    Total summary:
        { tag: { detail } }
    Detail summary:
        { category: { article: { tag: int } }
    """
    tracker.log("正在创建 Excel 文件", prt=True)
    # first write the summary page
    workbook = xlsxwriter.Workbook(path)
    # some format
    title_format = workbook.add_format({"bold": True})
    # create the summary worksheet
    summary = workbook.add_worksheet(name="总结")
    # init accum
    tracker.init_ticker(
        "   进程", "正在输出", 0,
        len(total_summary) +
        sum(len(tag_details) for tag_details in detail_summary.values()))
    row, col = 0, 0
    max_width = []
    summary.write_string(row, col, "词汇", cell_format=title_format)
    max_width.append(2 * WIDTH_RATIO)
    col += 1
    summary.write_string(row, col, "趋势标签", cell_format=title_format)
    max_width.append(4 * WIDTH_RATIO)
    col += 1
    if show_detail:
        summary.write_string(row, col, "拟合系数", cell_format=title_format)
        max_width.append(4 * WIDTH_RATIO)
        col += 1
        summary.write_string(row, col, "RMSE", cell_format=title_format)
        max_width.append(4 * WIDTH_RATIO)
        col += 1
    # write header
    cat_header = sorted(sorting.items(), key=lambda i: i[1])
    for category, _ in cat_header:
        summary.write_string(row, col, category, cell_format=title_format)
        max_width.append(len(category) * WIDTH_RATIO)
        col += 1
    row += 1
    col = 0
    # write values
    for tag, detail in total_summary.items():
        tracker.update_disc_fill("写入总结 {}".format(tag))
        tracker.tick()
        # write tag
        summary.write_string(row, col, tag)
        max_width[col] = max(len(tag) * WIDTH_RATIO, max_width[col])
        col += 1
        # write label
        label = detail["label"]
        if label is not None:
            label_name = TREND_NAME[label]
            summary.write_string(row, col, label_name)
            max_width[col] = max(len(label_name) * WIDTH_RATIO, max_width[col])
        else:
            summary.write_string(row, col, "-")
            max_width[col] = max(1, max_width[col])
        col += 1
        # write detail
        if show_detail:
            lr = detail["regression"]
            if lr is not None:
                coefficient, _, RMSE = lr
                summary.write_number(row, col, coefficient)
                max_width[col] = max(len(str(coefficient)), max_width[col])
                col += 1
                summary.write_number(row, col, RMSE)
                max_width[col] = max(len(str(RMSE)), max_width[col])
                col += 1
            else:
                summary.write_string(row, col, "-")
                max_width[col] = max(1, max_width[col])
                col += 1
                summary.write_string(row, col, "-")
                max_width[col] = max(1, max_width[col])
                col += 1
        # write
        occurrence = detail["occurrence"]
        for occ in occurrence:
            summary.write_number(row, col, occ)
            max_width[col] = max(len(str(occ)), max_width[col])
            col += 1
        row += 1
        col = 0
    for index, width in enumerate(max_width):
        summary.set_column(index, index, width=width)
    # write detail
    # { category: { tag: { article: int } }
    for category, _ in cat_header:
        tag_details = detail_summary[category]
        work_sheet = workbook.add_worksheet(category)
        row, col = 0, 0
        max_width = []
        work_sheet.write_string(row, col, "词汇", cell_format=title_format)
        max_width.append(2 * WIDTH_RATIO)
        col += 1
        # write header
        header = sorted(
            next(iter(tag_details.values())).keys(),
            key=lambda n: pinyin.get(n, format="strip", delimiter=" "))
        # write header
        for name in header:
            work_sheet.write_string(row, col, name, cell_format=title_format)
            max_width.append(len(name) * WIDTH_RATIO)
            col += 1
        row += 1
        col = 0
        # write values
        for tag, art_detail in tag_details.items():
            tracker.update_disc_fill("写入细节 {}".format(tag))
            tracker.tick()
            work_sheet.write_string(row, col, tag)
            max_width[col] = max(len(tag) * WIDTH_RATIO, max_width[col])
            col += 1
            for name in header:
                val = art_detail[name]
                work_sheet.write_number(row, col, val)
                max_width[col] = max(len(str(val)), max_width[col])
                col += 1
            row += 1
            col = 0
        for index, width in enumerate(max_width):
            work_sheet.set_column(index, index, width=width)
    tracker.log("正在关闭 Excel 文件", prt=True)
    workbook.close()
Exemple #11
0
    list6.extend(list5)
for i in list6:
    list2 = [k for k in i]

    if '-' in list2:
        num = list2.index('-')
        del list2[:num + 1]
    if ':' in list2:
        num = list2.index(':')
        del list2[:num + 1]
    for j in key:
        if j in list2:
            num = list2.index(j)
            del list2[num:]
    name = ''
    for l in list2:
        name = name + l
    list3.append(name)
list4 = [i for i in list3 if len(i) >= 2]
citylist = list4[10:]
pinyinlist = []
for i in citylist:
    citypinyin = pinyin.get(i, format='strip', delimiter=' ').split()
    pinyinlist.append(citypinyin)
cityname = input('请输入城市名:')
lastcityname = pinyinlist[citylist.index(cityname)][-1]
for i in pinyinlist:
    if i[0] == lastcityname:
        print(citylist[pinyinlist.index(i)])
        lastcityname = i[-1]
Exemple #12
0
 def myPinyin(strings):
     '''
     将汉字变为pinyin
     '''
     return pinyin.get(strings, format="strip",
                       delimiter="").replace('(', '_').replace(')', '_')
Exemple #13
0
    prov_list = rc.findall(html)

    # 获取所有的市
    rc = re.compile('\<dd.*?\>(.*?)\<\/dd\>')
    city_list = rc.findall(html)

    # data
    data = []
    data.append({"en": "beijing", "cn": "北京"})
    data.append({"en": "tianjin", "cn": "天津"})
    data.append({"en": "shanghai", "cn": "上海"})
    data.append({"en": "chongqing", "cn": "重庆"})

    for k in range(len(prov_list)):
        prov_dict = {}
        prov_dict['en'] = pinyin.get(prov_list[k])
        prov_dict['cn'] = prov_list[k]

        if k == 0 or k == len(prov_list) - 1:
            continue

        # 获取该省下的所有市
        rc = re.compile('\<a.*?\>(.*?)\<\/a\>')
        item_city = rc.findall(city_list[k])

        prov_dict['city'] = item_city
        data.append(prov_dict)

    for v in data:
        print('*' * 10)
        print("该省%s(%s)" % (v['cn'], v['en']))
Exemple #14
0
 def setChinese(self, chinese):
     self.chinese = chinese
     self.pinyin = pinyin.get(chinese)
Exemple #15
0
 def __init__(self, english, chinese):
     self.english = english
     self.chinese = chinese
     self.pinyin = pinyin.get(chinese)
Exemple #16
0
#!/bin/python2.7
#coding=utf-8
import os, sys
sys.path.append(os.path.dirname(os.getcwd()))
from models.empire.linkageModel import LinkageModel
from pinyin import pinyin
obj = LinkageModel("/data/cap/python/python_scripts/config/base.conf")
query = obj.getQuery()
num = 0
for item in query:
    if item.parent_id != 18:
        continue
    pinyinStr = pinyin.get(item.linkage_name, "", format="strip")
    item.pinyin = pinyinStr
    print item.linkage_name
    obj.session.commit()
Exemple #17
0
                    continue
                result.append({
                    "id": index,
                    "text": line_str[0],
                    "label": line_str[1].replace("\n", ""),
                    "exist": 1
                })
    # for i in range(len(result)):
    #     print(result[i])
    return result


def modify_line(file_path, line, content):
    file_path = "data/" + file_path + "/train.tsv"
    line += 1
    with open(file_path, 'r+', encoding='utf8') as f:
        cont = 1
        while True:
            cont += 1
            f.readline()
            if cont == int(line):
                f.seek(f.tell())
                f.write(content + "\n")
                break


if __name__ == '__main__':
    # page_list('data/fund_risk/train.tsv', 1)
    # modify_line('data/fund_risk/train.tsv', 1, "高收益~1~1")
    print(pinyin.get("诋毁其他基金管理人", format='strip'))
Exemple #18
0
 def get(self):
     params = self.parser.parse_args()
     file_page_query.modify_line(
         pinyin.get(params.get('modelName'), format='strip'),
         int(params.get('id')), params.get('data'))
     return {"code": 1, "message": "ok", "data": "ok"}
Exemple #19
0
 def get(self):
     params = self.parser.parse_args()
     modelName = params.get('modelName')
     modelPinYinName = pinyin.get(modelName, format='strip')
     shutil.copytree('data/base_data', 'data/' + modelPinYinName)
     return {"code": 1, "message": "ok", "data": modelPinYinName}
Exemple #20
0
from pinyin import pinyin
# 汉字中的间隔符delimiter
a = pinyin.get('杨强', format='strip', delimiter="")
print(a)
# 中间有空格
b = pinyin.get_initial('杨w强')
print(b.replace(' ', ''))