Browse Source

入库增加subject_id参数

莺声燕语 1 year ago
parent
commit
25a7ce8a2f
4 changed files with 27 additions and 14 deletions
  1. 1 1
      structure/danti_structure.py
  2. 16 3
      structure/structure_main.py
  3. 2 2
      utils/item_type_line.py
  4. 8 8
      utils/ruku_opera.py

+ 1 - 1
structure/danti_structure.py

@@ -120,7 +120,7 @@ def single_parse(one_item, item_type, wordid, subject):
             new_item_struct = option_structure(new_item_struct, res_list[0], new_item_struct["key"], 1, 1)
             if new_item_struct["errmsgs"]:
                 return ";;".join(new_item_struct["errmsgs"])
-            if any([True for i in new_item_struct['options'] if not i.replace(":", "").strip()]):  # 空选项中:被当成了内容
+            if 'options' in new_item_struct and any([True for i in new_item_struct['options'] if not i.replace(":", "").strip()]):  # 空选项中:被当成了内容
                 return "存在选项为空,请补充完整"
 
         new_item_struct["topic_num"] = item_ids[0] if item_ids else 0

+ 16 - 3
structure/structure_main.py

@@ -218,10 +218,23 @@ if __name__ == '__main__':
     # 6294326cf84c0e279ac6484e.html   62903acaf84c0e279ac647fb
     path2 = r"C:\Users\Python\Desktop\62d8eaaa6c6aff2279346c1e.html"
     # path2 = r"F:\zwj\Text_Structure\accept_files\62aae86a765759d85567a475.html"
-    html = open(path2, "r", encoding="utf-8").read()
+    # html = open(path2, "r", encoding="utf-8").read()
     # html = json.loads(html)  621845626ca622396925f55c
-    # html = ""
-    res1 = StructureExporter(html, "", "地理", 1).export()
+    html = """
+1. I’m anxious___________ your injury.Are you feeling any better now?
+2. After he was back on his feet, he was anxious___________ (return) to school as soon as possible.
+3. Helen was ___________ to death when she saw the ___________scene.She hid herself in the corner, shaking with___________(fright).
+4. The music outside___________ (annoy) Tom soon. He couldn’t keep his___________ (concentrate) with such ___________ (annoy) music going on yesterday.
+5. With so many people talking around, he still concentrated ___________ doing his homework,which left a deep impression on me.
+6. The result was far beyond ___________ we had expected, which brought great joy to every one of us.
+7. If the dress doesn’t fit you, take it back and you can exchange it ___________ another one of the same price.
+8. The dictionary is out of date:many words have been added ___________ the language since it came out.
+9. This vacation I went to an island on the Pacific and  ___________ by its scenery. The island has left a lasting ___________ on me.
+10. We are confident about the future and will never lose our confidence  ___________ the achievements we will make.
+11. He has worked for nearly 20 years, so he is senior ___________ most of his workmates.
+12. Although he is three years junior ___________ me, he has more work experience.
+    """
+    res1 = StructureExporter(html, "", "语文", 1).export()
     # new_fpath = os.path.join(r"G:\zwj\WL\Text_Structure\fail_files", "res_政治.json")
     # re_f = open(new_fpath, 'w', encoding='utf-8')
     # json.dump(res1[0]["items"], re_f, ensure_ascii=False)

+ 2 - 2
utils/item_type_line.py

@@ -208,12 +208,12 @@ def get_item_head_info_cn(items_str):
         if len(a) > 3 and a[3] and re.search(pattern3, a[3]):
             info3 = re.search(pattern3, a[3])
             type_num = (str(info3.group(1)) + str(info3.group(3))).replace('None', '')
-            title_type_num.append((cur_type, int(type_num)))
+            title_type_num.append([cur_type, int(type_num)])
             # if info3.group(2) and not each_item_score[k] and \
             #         all_type[k].replace("题", "") in ["单选", "不定选择", "多选", "选择"]:
             #     each_item_score[k] = float(info3.group(2)) / int(type_num)
         else:
-            title_type_num.append((cur_type, 0))
+            title_type_num.append([cur_type, 0])
         if len(a) > 3 and a[3] and re.search(pattern4, a[3]):
             info4 = re.search(pattern4, a[3])
             total_score.append(float(info4.group(1)))

+ 8 - 8
utils/ruku_opera.py

@@ -250,7 +250,7 @@ class Ruku():
                res_zyk = {"data":{"html": xxx, "items": xxx}, "errcode": 0, "errmsgs": ""}
                res_xbk = {"items": xxx, "errcode": 0, "errmsg":"ok"}
         """
-        res_xbk = {"items": [], "errcode": 0, "errmsg": "ok", "callback_type": 2}
+        res_xbk = {"items": [], "errcode": 0, "errmsg": "ok", "callback_type": 2, "subject_id": self.subject}
         res_zyk = {"errcode": 0, "errmsgs": "", "data": {"html": self.htmlt, "items": self.items_list}}
         # 1>>判断删除腾讯云桶内图片
         if self.source not in ["teacher", "xue_guan"]:  # {"xue_guan": "1", "teacher": "2", "ai": "3"}
@@ -260,7 +260,7 @@ class Ruku():
         # 2>>mathjax渲染的svg图片提取->保存->格式转化
         svg_convert_res = self.mathjx2png()
         if type(svg_convert_res) == str:
-            res_xbk = {"items": [], "errcode": 1, "errmsg": svg_convert_res, "callback_type": 2}
+            res_xbk = {"items": [], "errcode": 1, "errmsg": svg_convert_res, "callback_type": 2, "subject_id": self.subject}
             res_zyk = {"errcode": 1, "errmsgs": svg_convert_res, "data": {}}
             if self.callback_url:
                 self.callback_user(res_xbk, self.callback_url)
@@ -379,7 +379,7 @@ class Ruku():
                     if self.source != "xue_guan":
                         repeat_r, repeat_time = self.repeat_check(nn, one_items, repeat_time)
                         if type(repeat_r) == str:
-                            res_xbk = {"items": [], "errcode": 1, "errmsg": repeat_r, "callback_type": 2}
+                            res_xbk = {"items": [], "errcode": 1, "errmsg": repeat_r, "callback_type": 2, "subject_id": self.subject}
                             res_zyk = {"errcode": 1, "errmsgs": repeat_r, "data": {}}
                             self.callback_user(res_xbk, self.callback_url)
                             return res_zyk
@@ -418,9 +418,9 @@ class Ruku():
                                         "paper_id": self.wordid,
                                         "img_upload_time": img_upload_time}, ensure_ascii=False))
                 res_zyk = {"data": {"html": self.htmlt, "items": items_res_to_zyk}, "errcode": 0, "errmsgs": ""}
-                res_xbk = {"items": items_res_to_xbk, "errcode": 0, "errmsg": "ok", "callback_type": 2}
+                res_xbk = {"items": items_res_to_xbk, "errcode": 0, "errmsg": "ok", "callback_type": 2, "subject_id": self.subject}
             except Exception as e:
-                res_xbk = {"items": [], "errcode": 1, "errmsg": "公式或图片上传腾讯云失败", "callback_type": 2}
+                res_xbk = {"items": [], "errcode": 1, "errmsg": "公式或图片上传腾讯云失败", "callback_type": 2, "subject_id": self.subject}
                 res_zyk = {"data":{"html": self.htmlt, "items": self.items_list}, "errcode": 1,
                            "errmsgs": "公式或图片上传腾讯云失败"}
                 logger.info(json.dumps({"log_level": "warn",
@@ -437,7 +437,7 @@ class Ruku():
                     if self.source != "xue_guan":
                         repeat_r, repeat_time = self.repeat_check(nn, one_items, repeat_time)
                         if type(repeat_r) == str:
-                            res_xbk = {"items": [], "errcode": 1, "errmsg": repeat_r, "callback_type": 2}
+                            res_xbk = {"items": [], "errcode": 1, "errmsg": repeat_r, "callback_type": 2, "subject_id": self.subject}
                             res_zyk = {"errcode": 1, "errmsgs": repeat_r, "data": {}}
                             self.callback_user(res_xbk, self.callback_url)
                             return res_zyk
@@ -449,7 +449,7 @@ class Ruku():
                     new_one_item.update(one_items)
                     items_res_to_xbk.append(new_one_item)
 
-                res_xbk = {"items": items_res_to_xbk, "errcode": 0, "errmsg": "ok", "callback_type": 2}
+                res_xbk = {"items": items_res_to_xbk, "errcode": 0, "errmsg": "ok", "callback_type": 2, "subject_id": self.subject}
                 logger.info(json.dumps({"log_level": "info",
                                         "paper_id": self.wordid,
                                         "repeat_time": repeat_time}, ensure_ascii=False))
@@ -497,7 +497,7 @@ class Ruku():
         入口函数
         :return:
         """
-        res_xbk = {"items": [], "errcode": 1, "errmsg": "保存失败", "callback_type": 2}
+        res_xbk = {"items": [], "errcode": 1, "errmsg": "保存失败", "callback_type": 2, "subject_id": self.subject}
         try:
             res_zyk = self.upload_img()
             return res_zyk