structure_main.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. #!/usr/bin/env/python
  2. # -*- coding:utf-8 -*-
  3. from pprint import pprint
  4. from typing import Any
  5. # from utils.exam_type import get_exam_type
  6. # from utils.get_data import Mongo
  7. from structure.final_structure import one_item_structure
  8. from utils.stem_ans_split import get_split_pos
  9. from utils.washutil import *
  10. from utils.washutil_for_DL_way import HtmlWash_2
  11. from structure.three_parse_structure import *
  12. from utils.pic_pos_judge import img_regroup
  13. from func_timeout import func_set_timeout
  14. import requests
  15. from structure.ans_structure import get_ans_match
  16. from utils.xuanzuoti2slave import toslave_bef, toslave_aft
  17. logger = configs.myLog(__name__, log_cate="reparse_ruku_log").getlog()
  18. paper_types = ["第三种试卷格式:题目与答案分开",
  19. "第二种试卷格式: 不同时含有或都不含有{答案}和{解析}关键字",
  20. "第一种试卷格式:教师用卷,含答案和解析关键字"]
  21. class WordParseStructure:
  22. """
  23. 基于wordbin出来的html结果进一步做 试卷类型 非模板结构化
  24. """
  25. def __init__(self, html, wordid, is_reparse=0, must_latex=0, source="zxhx", subject="数学"):
  26. self.html = html
  27. self.is_reparse = is_reparse
  28. self.wordid = wordid
  29. self.must_latex = must_latex
  30. self.source = source
  31. self.subject = subject
  32. def __call__(self):
  33. if self.source not in ["school"]: # == "school" "xue_guan", "teacher":
  34. res = self.structure_combine_DL()
  35. if not res[0]:
  36. return self.structure()
  37. logger.info("----【paper_id:{}】采用切题服务".format(self.wordid))
  38. return res
  39. else:
  40. return self.structure()
  41. def structure_combine_DL(self):
  42. # 第一步:清洗
  43. htmltext, row_list, new_html = HtmlWash_2(self.html, self.wordid, self.is_reparse,
  44. must_latex=self.must_latex).html_cleal()
  45. if not row_list:
  46. return {"errcode": 1, "errmsgs": "题文没有有效信息", "data": {}}, ""
  47. # 第二步:寻找题目和答案的切分点,一定要有“答案”关键字
  48. split_res = get_split_pos(row_list)
  49. if type(split_res) == str:
  50. return {"errcode": 1, "errmsgs": split_res, "data": {}}, paper_types[0]
  51. row_list, items_list, ans_list, _ = split_res
  52. rd1_may_fail = 0
  53. paper_type = ""
  54. item_res = {}
  55. if "【答案】" in "".join(items_list) or "【解析】" in "".join(items_list):
  56. rd1_may_fail = 1
  57. elif items_list:
  58. paper_type = "第三种试卷格式:题目与答案分开"
  59. try:
  60. r1 = requests.post(url=configs.topic_segment_ip,
  61. json={"content": "<br>".join(items_list), "subject": self.subject,
  62. "paper_id": self.wordid, "text_type": "stem_block"})
  63. item_res = r1.json()["res"]
  64. # print(item_res)
  65. r2 = requests.post(url=configs.topic_segment_ip,
  66. json={"content": "<br>".join(ans_list), "subject": self.subject,
  67. "paper_id": self.wordid, "text_type": "answer_block"})
  68. all_ans, ans_no = r2.json()["res"]
  69. # print(1111111111111,all_ans)
  70. print(ans_no)
  71. # 根据ans_no纠正切错的all_ans,如[2, 6, 4, None, 7, None, 5, None, 1]
  72. if abs(len([i for i in ans_no if i]) - len(item_res)) <= 2:
  73. last_idx = None
  74. new_ans_no = ans_no.copy()
  75. for i, no in enumerate(ans_no):
  76. if no is not None:
  77. last_idx = i
  78. if i > 0 and no is None and last_idx is not None:
  79. all_ans[last_idx] += "\n"+all_ans[i]
  80. all_ans[i] = ""
  81. new_ans_no[i] = "del"
  82. all_ans = [j for j in all_ans if j]
  83. ans_no = [i for i in new_ans_no if i != 'del']
  84. if abs(len(ans_no) - len(item_res)) > 2:
  85. item_res = ans_block_split(ans_list, item_res)
  86. else:
  87. item_res = get_ans_match(item_res, all_ans, ans_no, {}, 'model_split')
  88. except Exception as e:
  89. logger.info("----【paper_id:{}】切题服务异常:{}".format(self.wordid, e))
  90. else:
  91. rd1_may_fail = 1
  92. if rd1_may_fail:
  93. try:
  94. r3 = requests.post(url=configs.topic_segment_ip,
  95. json={"content": htmltext, "subject": self.subject,
  96. "paper_id": self.wordid, "text_type": "stem_block"})
  97. item_res = r3.json()["res"]
  98. # 还需判断下教师卷
  99. for k, one_res in enumerate(item_res):
  100. if re.search('\n【(答案|[解分][析答]|详解|点[评睛]|考点|专题)】', one_res["stem"]):
  101. case = "case1" # 默认有“答案”关键字
  102. if re.search(r'\n【答案】|[\n】]\s*答案\s*[::]', one_res["stem"]) is None:
  103. # 没“答案”关键字
  104. case = "case0"
  105. dd1 = stem_ans_split(one_res, case) # 对切分后的每道题再细分
  106. one_res["stem"] = dd1["stem"]
  107. del dd1["stem"]
  108. one_res.update(dd1)
  109. else: # 没有解析的情况
  110. one_res.update({"key": "", "parse": ""})
  111. except Exception as e:
  112. logger.info("----【paper_id:{}】切题服务异常:{}".format(self.wordid, e))
  113. # ==========小题结构化========
  114. if item_res:
  115. # 答案解析字段完善
  116. for i, one_item in enumerate(item_res):
  117. if 'key' not in one_item:
  118. item_res[i]['key'] = ""
  119. if 'parse' not in one_item:
  120. item_res[i]['parse'] = ""
  121. # 单题结构化
  122. consumer = ['noslave'] * len(item_res)
  123. items_no_type = [1] * len(item_res)
  124. xyz = zip(item_res, consumer, items_no_type)
  125. res = list(map(one_item_structure, xyz)) # 和多进程相比,这样速度也很快
  126. # pprint(res)
  127. # ==========最后的清洗=========
  128. res = wash_after(res, self.subject)
  129. # 针对模型可能切错的地方纠正,放在切割模型预测中纠正了
  130. # for i, one_item in enumerate(res):
  131. # if i>0 and one_item['topic_num'] is None and res[i-1]['topic_num'] is not None and res[i+1]['topic_num'] is not None \
  132. # and res[i+1]['topic_num'] - res[i-1]['topic_num'] == 1 and not one_item['key'] and not one_item['parse']:
  133. # if res[i-1]["parse"]:
  134. # res[i - 1]["parse"] += one_item['stem']
  135. # del res[i]
  136. # elif res[i-1]["key"]:
  137. # res[i - 1]["key"] += one_item['stem']
  138. # del res[i]
  139. # pprint(res)
  140. # 结果返回
  141. if self.is_reparse:
  142. return {"html":new_html, "items": res}, paper_type
  143. else:
  144. return {"items": res}, paper_type
  145. else:
  146. return {}, paper_type
  147. def img_repl(self, one_dict):
  148. """
  149. 初步拆分题目后,图片信息的替换
  150. :return:
  151. """
  152. imgs = {s: re.findall("<img.*?/>", one_dict[s]) for s in ['stem', 'key', 'parse']}
  153. for k, imgs_seq in imgs.items():
  154. for img in imgs_seq:
  155. img = re.sub("(?<!\s)(w_h|data-latex)=", r" \1=", img)
  156. if img in self.subs2src:
  157. one_dict[k] = one_dict[k].replace(img, self.subs2src[img])
  158. # if type(self.img_url) == str and self.img_url:
  159. # one_dict[k] = re.sub(r'<img src="files/', '<img src="' + str(self.img_url), str(one_dict[k]))
  160. if "analy" in one_dict:
  161. for img in re.findall("<img.*?/>", one_dict["analy"]):
  162. img = re.sub("(?<!\s)(w_h|data-latex)=", r" \1=", img)
  163. one_dict["analy"] = one_dict["analy"].replace(img, self.subs2src[img])
  164. return one_dict
  165. # @func_set_timeout(30)
  166. def structure(self):
  167. """结构化入口"""
  168. # 第一步:清洗
  169. row_list, self.subs2src, new_html = HtmlWash(self.html, self.wordid, self.is_reparse,
  170. must_latex=self.must_latex).html_cleal()
  171. # pprint(row_list)
  172. if not row_list:
  173. return {"errcode": 1, "errmsgs": "题文没有有效信息", "data": {}}, ""
  174. # 判断考试类型
  175. # paper_other_info = get_exam_type(row_list)
  176. # 第二步:寻找题目和答案的切分点,一定要有“答案”关键字
  177. split_res = get_split_pos(row_list)
  178. if type(split_res) == str:
  179. return {"errcode": 1, "errmsgs": split_res, "data": {}}, paper_types[0]
  180. row_list, items_list, ans_list, is_may_ans = split_res
  181. rd2_is_fail = 0
  182. rd1_may_fail = 0
  183. item_res, paper_type, item_no_type = "", "", 1
  184. if "【答案】" in "".join(items_list) or "【解析】" in "".join(items_list):
  185. rd1_may_fail = 1
  186. else:
  187. if items_list:
  188. paper_type = paper_types[0]
  189. reform_res = items_ans_reform(items_list, ans_list)
  190. if type(reform_res) == str:
  191. return {"errcode": 1, "errmsgs": reform_res, "data": {}}, paper_type
  192. else:
  193. if len(reform_res)==2:
  194. item_res = reform_res
  195. else:
  196. item_res, item_no_type, rd2_is_fail = reform_res
  197. if not items_list or rd1_may_fail or (is_may_ans and rd2_is_fail):
  198. ans_n = re.findall("【答案】", "\n".join(row_list))
  199. if ans_n and len(ans_n) == len(re.findall("【解析】", "\n".join(row_list))) > 10: # 带相同个数的答案和解析
  200. paper_type = paper_types[2]
  201. item_res = split_by_keywords(row_list)
  202. if type(item_res) == str and re.search("格式有误|没有换行|题型不明确|题型行格式有问题", item_res):
  203. print("第一种试卷格式解析格式有误")
  204. try:
  205. paper_type = paper_types[1]
  206. item_res = split_by_topicno(row_list)
  207. except:
  208. return {"errcode": 1, "errmsgs": item_res, "data": {}}, paper_type
  209. else:
  210. paper_type = paper_types[1]
  211. item_res = split_by_topicno(row_list)
  212. if type(item_res) == str:
  213. return {"errcode": 1, "errmsgs": item_res, "data": {}}, paper_type
  214. else:
  215. item_list = item_res
  216. if type(item_res) == tuple:
  217. item_list, item_no_type = item_res
  218. # pprint(item_list)
  219. print('****************初步切分题目的个数*****************', len(item_list))
  220. res = []
  221. if item_list:
  222. item_list = img_regroup(item_list, row_list) # 图片重组判断
  223. if self.subs2src:
  224. item_list = list(map(self.img_repl, item_list)) # 图片信息替换还原
  225. # ---------初步拆分题目错误判断--------------------
  226. # ---------新题型进一步拆分--------------------
  227. # new_item = [[k, i] for k, i in enumerate(item_list) if re.search("选[修学考]", i["stem"][:10])]
  228. # have_slave = 0
  229. # to_slave = {}
  230. # if new_item:
  231. # try:
  232. # have_slave = 1
  233. # for one in new_item:
  234. # new_res = toslave_bef(one[1])
  235. # item_list[one[0]] = new_res
  236. # if type(new_res) == list:
  237. # to_slave[one[0]] = new_res
  238. # except:
  239. # pass
  240. # if to_slave:
  241. # item_list = [i if type(i) == list else [i] for i in item_list]
  242. # item_list = sum(item_list, [])
  243. # ==========小题结构化========
  244. # from multiprocessing.dummy import Pool as ThreadPool
  245. # pool = ThreadPool(2) # 比# pool = multiprocessing.Pool(3)速度快
  246. consumer = ['toslave'] * len(item_list)
  247. items_no_type = [item_no_type] * len(item_list)
  248. xyz = zip(item_list, consumer, items_no_type)
  249. # res = list(pool.map(one_item_structure, xyz))
  250. res = list(map(one_item_structure, xyz)) # 和多进程相比,这样速度也很快
  251. # pprint(res)
  252. # ==========最后的清洗=========
  253. res = wash_after(res)
  254. # if have_slave and not to_slave:
  255. # res = list(map(toslave_aft, res))
  256. # 结果返回
  257. if self.is_reparse:
  258. return {"html":new_html, "items": res}, paper_type
  259. else:
  260. return {"items": res}, paper_type
  261. @staticmethod
  262. def _get_all_errors(res):
  263. """
  264. 整套试卷结构化完成以后,把所有报错放在一个list里面:
  265. all_errors = [{"单选题第1题目":[]},{"解答题第2题":[]},{},{}]
  266. :param res:
  267. :return:
  268. """
  269. type_names = []
  270. errmgs = []
  271. spliterr_point = []
  272. for one_res in res:
  273. type_names.append(one_res["type"])
  274. if "text_errmsgs" in one_res:
  275. errmgs.append(one_res["text_errmsgs"])
  276. else:
  277. errmgs.append("")
  278. if 'spliterr_point' in one_res:
  279. spliterr_point.append(one_res['spliterr_point'])
  280. # 给同种题型的名字重新编码
  281. new_names = []
  282. for k, v in enumerate(type_names):
  283. if v:
  284. nums = str(type_names[:k]).count(v)
  285. else:
  286. nums = k
  287. if spliterr_point:
  288. add_n = insert_sort2get_idx(spliterr_point, k+1)
  289. new_names.append("{}第{}题(在整份word中的序号为{}题)".format(v, nums + 1 + add_n, k + 1 + add_n))
  290. else:
  291. new_names.append("{}第{}题(在整份word中的序号为{}题)".format(v, nums + 1, k + 1))
  292. all_errors = []
  293. for name, error in zip(new_names, errmgs):
  294. if len(error) > 0:
  295. all_errors.append({name: error})
  296. return all_errors
  297. if __name__ == '__main__':
  298. # 单份试卷测试
  299. import json
  300. from bson.objectid import ObjectId
  301. # path1 = r"F:\zwj\parse_2021\data\fail\2\2.txt"
  302. # path = r"F:\zwj\parse_2021\res_folder\13.html"
  303. # images_url1 = "" # "http://49.233.23.58:11086/ser_static/4439/files/"
  304. # html = "<p>"+"</p>\n<p>".join(html.split("\n"))+"</p>"
  305. # with open(r"F:\zwj\Text_Structure\fail_files3\c5e222c5fbded2a2264ae002907fc92c__2021_04_16_18_43_23.json", 'r') as load_f:
  306. # html = json.load(load_f)
  307. # print(load_dict)
  308. # path2 = r"C:\Users\Python\Desktop\bug\5-9\663c90361ec1003b58557474.html"
  309. path2 = r"F:\zwj\Text_Structure\accept_files\664597dd71453ba19c20977f.html"
  310. # path2 = r"C:\Users\Python\Desktop\bug\6419746d11a1cdad550f5502.html"
  311. # path2 = r"F:\zwj\Text_Structure\new_tiku_structure_v3_sci\data\620bbf7aa7d375f4518b98e1.html"
  312. # path2 = r"F:\zwj\new_word_text_extract_v2\data\地理\2\2020-2021学年广东省揭阳市揭西县五校九年级(下)第二次联考地理试卷-普通用卷.html"
  313. # path2 = r"F:\zwj\new_word_parse_2021\data\huaxue\huexue2.html"
  314. # path2 = r"C:\Users\Python\Desktop\bug\6258cc7af84c0e279ac64301.html" # 正则卡死
  315. # path2 = r"C:\Users\Python\Desktop\bug\629073b9f84c0e279ac64811.html" # 正则卡死
  316. # 62650d5cf84c0e279ac643f1 6258cc7af84c0e279ac64301 62660fa2f84c0e279ac643f5
  317. html = open(path2, "r", encoding="utf-8").read()
  318. # html = """
  319. # <html><head><meta charset="utf-8" /></head><body>\n<p>1.下列化学符号中的数字“<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image1.png" width="13px" height="17px" data-latex="$$" />”表示的意义不正确的是</p>\n<p>A.<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image2.png" width="21px" height="24px" data-latex="$$" />:“<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image1.png" width="13px" height="17px" data-latex="$$" />”表示两个氧原子</p>\n<p>B.<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image3.png" width="34px" height="24px" data-latex="$$" />:“<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image1.png" width="13px" height="17px" data-latex="$$" />”表示一个二氧化氮分子含有两个氧原子</p>\n<p>C.<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image4.png" width="40px" height="21px" data-latex="$$" />:“<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image1.png" width="13px" height="17px" data-latex="$$" />”表示两个氢氧根离子</p>\n<p>D.<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image5.png" width="36px" height="28px" data-latex="$$" />:“<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image6.png" width="21px" height="17px" data-latex="$$" />”表示氧化镁中镁元素的化合价为<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image6.png" width="21px" height="17px" data-latex="$$" />价</p>\n<p>【答案】</p>\n<p>A</p>\n<p>【解析】</p>\n<p>根据元素符号前面的数字表示原子的个数,元素符号右下角的数字表示一个分子中的原子个数,离子符号前面的数字表示离子的个数,元素符号正上方的数字表示元素的化合价。A.<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image2.png" width="21px" height="24px" data-latex="$$" />:“<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image1.png" width="13px" height="17px" data-latex="$$" />”表示一个氧分子由两个氧原子组成,故选项表示的意义不正确;B.元素符号右下角的数字表示一个分子中的原子个数,故<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image3.png" width="34px" height="24px" data-latex="$$" />:“<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image1.png" width="13px" height="17px" data-latex="$$" />”表示一个二氧化氮分子含有两个氧原子,故表示的意义正确;C.离子符号前面的数字表示离子的个数,故<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image4.png" width="40px" height="21px" data-latex="$$" />:“<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image1.png" width="13px" height="17px" data-latex="$$" />”表示两个氢氧根离子,故表示的意义正确;D.元素符号正上方的数字表示元素的化合价,故<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image7.png" width="36px" height="28px" data-latex="$$" />中的“<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image1.png" width="13px" height="17px" data-latex="$$" />”表示镁元素的化合价为<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image6.png" width="21px" height="17px" data-latex="$$" />价,故表示的意义正确。故选:A。</p>\n<p> </p>\n<p>2.亚油酸具有降低人体血液中胆固醇及血脂的作用,它的化学式为<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image8.png" width="64px" height="24px" data-latex="$$" />,下列说法中正确的是</p>\n<p>A.亚油酸是由三个元素构成的化合物</p>\n<p>B.每个亚油酸分子中含有<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image9.png" width="20px" height="18px" data-latex="$$" />个原子</p>\n<p>C.亚油酸中碳.氧元素的质量比为<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image10.png" width="38px" height="18px" data-latex="$$" /></p>\n<p>D.每个亚油酸分子中含有<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image11.png" width="18px" height="18px" data-latex="$$" />个碳原子、<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image12.png" width="20px" height="18px" data-latex="$$" />个氢原子、<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image13.png" width="9px" height="17px" data-latex="$$" />个氧分子</p>\n<p>【答案】</p>\n<p>C</p>\n<p>【解析】</p>\n<p>A.由化学式可知,亚油酸是由<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image14.png" width="16px" height="18px" data-latex="$$" />、<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image15.png" width="17px" height="17px" data-latex="$$" />、<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image16.png" width="16px" height="18px" data-latex="$$" />三种元素组成的化合物,A错误。B.每个亚油酸分子中含有<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image17.png" width="102px" height="18px" data-latex="$$" />个原子,B错误。C.亚油酸中碳.氧元素的质量比为<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image18.png" width="184px" height="18px" data-latex="$$" />,C正确。D.每个亚油酸分子中含有<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image11.png" width="18px" height="18px" data-latex="$$" />个碳原子、<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image12.png" width="20px" height="18px" data-latex="$$" />个氢原子、<img src="http://192.168.1.140:8800/ser_static/1638177060408824/word/media/image19.png" width="13px" height="17px" data-latex="$$" />个氧原子,D错误。故选:C。</p>\n</body></html>
  320. # """
  321. # print(html)
  322. # html = "\n1、已知集合M满足{1,2}≤M≤{1,2,5,6,7},则\n符合条件的集合M有__个."
  323. res1 = WordParseStructure(html, "664597dd71453ba19c20977f",
  324. is_reparse=0, must_latex=0,
  325. source="ai", subject="物理")()
  326. # new_fpath = os.path.join(r"F:\zwj\Text_Structure\fail_files", "res1.html")
  327. # re_f = open(new_fpath, 'a+', encoding='utf-8')
  328. # for i in res1[0]["items"]:
  329. # re_f.write(str(i))
  330. # pprint(res1)
  331. pprint(res1[0]['items'])
  332. print('题目数量:', len(res1[0]["items"]))
  333. # new_fpath = r"F:\zwj\Text_Structure\new_tiku_structure_2021\res_folder\10-28.json"
  334. # re_f = open(new_fpath, 'w', encoding='utf-8')
  335. # json.dump(res1, re_f, ensure_ascii=False)
  336. # mongo = Mongo()
  337. # data = mongo.get_data_info({"_id": ObjectId("5fc64c9c4994183dda7e75b2")})
  338. # # pprint(data["item_ocr"])
  339. # res1 = WordParseStructure(data["item_ocr"], images_url1).structure()
  340. # print(res1)
  341. # print('题目数量:', len(res1[0]["items"]))
  342. # 6837 序号有些乱 6836 图片位置和格式有问题
  343. # 6822 16A、和16B、类型的序号怎么处理 'item_id'有int和 str 型,须统一处理下
  344. # 6820 答案页没有明显标识
  345. # 14.html 只有答案,没有题干
  346. # 21.html 多套题目在一起,多个从1开始的序号,最后一道题,把后面题目都放在一起了,需要判断一下吗?
  347. # import json
  348. # re_f = open("207.txt", 'w', encoding='utf-8')
  349. # json.dump(res1[0], re_f)
  350. # json文件
  351. # for file in os.listdir(r"F:\zwj\Text_Structure\fail_files"):
  352. # path1 = os.path.join(r"F:\zwj\Text_Structure\fail_files", file)
  353. # # path1 = r"F:\zwj\Text_Structure\fail_files\89a6911f57bf89aba898651b27d2a2fc__2021_04_09_18_50_19.json"
  354. # with open(path1,'r',encoding='utf-8') as f:
  355. # html= json.load(f)
  356. # pprint(html)
  357. # # try:
  358. # # res1 = WordParseStructure(html, "").structure()
  359. # # os.remove(path1)
  360. # # except:
  361. # # pass
  362. # res1 = WordParseStructure(html, "").structure()
  363. # pprint(res1)
  364. # print('题目数量:', len(res1[0]["items"]))