ocr_key_words.py 239 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932
  1. import re
  2. def find_repeat(source, elmt): # 去重后重新定位数字索引
  3. elmt_index = []
  4. s_index = 0
  5. e_index = len(source)
  6. while (s_index < e_index):
  7. try:
  8. temp = source.index(elmt, s_index, e_index)
  9. elmt_index.append(temp)
  10. s_index = temp + 1
  11. except ValueError:
  12. break
  13. return elmt_index
  14. def ocr_key_words(rect,type_score_dict): # 将ocr识别得到的文字与模型得到的type_score对应
  15. '''
  16. :param rect: OCR识别结果数组,格式:res = {'chars': [},'coordinates': [(),()},'words': []}
  17. :param type_score_dict: 模型得到的type_score(与模型得到的边框相对应)
  18. :return: 字典中添加word
  19. '''
  20. len_ocr = len(rect['chars'])
  21. xmin = type_score_dict['type_box'][0]
  22. ymin = type_score_dict['type_box'][1]
  23. xmax = type_score_dict['type_box'][2]
  24. ymax = type_score_dict['type_box'][3]
  25. words=[]
  26. for j in range(len_ocr):
  27. if rect['coordinates'][j][0] - xmin > -30 and rect['coordinates'][j][1] - ymin > -30 and rect['coordinates'][j][2] - xmax < 30 and rect['coordinates'][j][3] - ymax < 30:
  28. word = rect['chars'][j]
  29. words.append(word)
  30. type_score_dict['words']= words
  31. type_score_dict_ocr = type_score_dict
  32. return type_score_dict_ocr
  33. def key_words(type_score_dict_ocr): # 根据OCR结果结合关键字解析
  34. total_score = 0
  35. volume_score = 0
  36. volume_structure_item = 0
  37. volume_structure = []
  38. Score_structure_item = 0
  39. Score_structure = []
  40. all_structure = {}
  41. keyword_volume = ['第卷', '第部']
  42. keyword_type = ['选择', '非选择题', '综合题', '问答题', '主观题', '客观题', '解答题','计算题']
  43. len_keyword_type = len(keyword_type)
  44. keyword_item1 = ['共分', '合计分', '总共分', '总计分', '小题满分', '本小题', '满分', '共计', '共.分', '合计.分', '总共.分', '总计.分', '小题满分.','本小题.', '满分.', '共计.']
  45. len_keyword_item1 = len(keyword_item1)
  46. keyword_item2 = ['每题分', '每小题分', '空分', '每小题.分', '每题.分', '空.分'] # '分/题'暂未考虑
  47. len_keyword_item2 = len(keyword_item2)
  48. keyword_item3 = ['共题', '共小题', '分小题', '本题小题', '共个小题', '分为小题', '分个小题','本大题共小题']
  49. len_keyword_item3 = len(keyword_item3)
  50. keyword_item4 = ['分']
  51. len_keyword_item4 = len(keyword_item4)
  52. keyword_item5 = ['分/题']
  53. len_keyword_item5 = len(keyword_item5)
  54. keyword_item5 = ['题', '.', '、']
  55. ocr_1 = type_score_dict_ocr['words']
  56. s = ''.join((str(x) for x in ocr_1)) # 合并为一个字符串
  57. if s.find('IV') != -1 or s.find('Ⅳ') != -1:
  58. s = s.replace('Ⅳ', '4')
  59. s = s.replace('IV', '4')
  60. elif s.find('III') != -1 or s.find('Ⅲ') != -1:
  61. s = s.replace('Ⅲ', '3')
  62. s = s.replace('III', '3')
  63. elif s.find('II') != -1 or s.find('Ⅱ') != -1:
  64. s = s.replace('Ⅱ', '2')
  65. s = s.replace('II', '2')
  66. elif s.find('VI') != -1 or s.find('Ⅵ') != -1:
  67. s = s.replace('Ⅵ', '6')
  68. s = s.replace('VI', '6')
  69. elif s.find('VII') != -1 or s.find('Ⅶ') != -1:
  70. s = s.replace('Ⅶ', '7')
  71. s = s.replace('VII', '7')
  72. elif s.find('VIII') != -1 or s.find('Ⅷ') != -1:
  73. s = s.replace('Ⅷ', '8')
  74. s = s.replace('VIII', '8')
  75. elif s.find('IX') != -1 or s.find('Ⅸ') != -1:
  76. s = s.replace('Ⅸ', '9')
  77. s = s.replace('IX', '9')
  78. elif s.find('X') != -1 or s.find('Ⅹ') != -1:
  79. s = s.replace('Ⅹ', '10')
  80. s = s.replace('X', '10')
  81. elif s.find('I') != -1 or s.find('Ⅰ') != -1:
  82. s = s.replace('Ⅰ', '1')
  83. s = s.replace('I', '1')
  84. elif s.find('V') != -1 or s.find('Ⅴ') != -1:
  85. s = s.replace('Ⅴ', '5')
  86. s = s.replace('V', '5')
  87. C_s = re.sub("[A-Za-z0-9\!\%\[\]\,\。]", "", s) # 提取汉字
  88. E_s = ''.join(re.findall(r'[A-Za-z]', s)) # 提取英文字符
  89. N_s = re.findall('\d+', s) # 提取阿拉伯数字
  90. if len(N_s) == 1 and len(N_s[0]) < 6 and len(E_s) == 0 and (C_s == keyword_item5[0] or C_s == keyword_item5[1] or len(C_s) == 0):
  91. type_score_dict_ocr['item_N'] = int(N_s[0])
  92. type_score_dict_ocr['item_total_score'] = -1
  93. type_score_dict_ocr['item_count'] = -1
  94. type_score_dict_ocr['item_score'] = -1
  95. Score_structure_item = type_score_dict_ocr
  96. Score_structure.append(Score_structure_item)
  97. all_structure = {'volume_structure': -1,
  98. 'Score_structure': Score_structure}
  99. elif N_s != []:
  100. for iiii in range(len(keyword_volume)):
  101. Score_structure_item = {}
  102. if C_s.find(keyword_volume[iiii]) != -1:
  103. '''
  104. 对应试卷中存在分卷信息的情况,根据包含数字的个数分为5类,暂定包含信息的有效数字个数小于5,并处理小题分数和总分可能包含小数点的情况
  105. 暂定小题个数不包含小数
  106. 暂定总分数中不存在有意义的小数位
  107. '''
  108. if len(N_s) == 1:
  109. num_index = s.index(N_s[0])
  110. num_infer = s[num_index - len(N_s[0])]
  111. num_back = s[num_index + len(N_s[0])]
  112. if num_back == '分': # 第卷/部*分
  113. volume_score = int(N_s[0])
  114. type_score_dict_ocr['volume_N'] = -1
  115. type_score_dict_ocr['volume_total_score'] = volume_score
  116. type_score_dict_ocr['volume_count'] = -1
  117. type_score_dict_ocr['volume_score'] = -1
  118. elif num_back == '卷' or num_back == '部': # 第*卷
  119. volume_N = int(N_s[0])
  120. type_score_dict_ocr['volume_N'] = volume_N
  121. type_score_dict_ocr['volume_total_score'] = -1
  122. type_score_dict_ocr['volume_count'] = -1
  123. type_score_dict_ocr['volume_score'] = -1
  124. elif len(N_s) == 2:
  125. num_index1 = s.index(N_s[0])
  126. num_infer1 = s[num_index1 - len(N_s[0])]
  127. num_back1 = s[num_index1 + len(N_s[0])]
  128. all_1 = find_repeat(s, N_s[1])
  129. temp1 = 0
  130. for ii in range(len(N_s[0])):
  131. if N_s[0][ii] == N_s[1]:
  132. temp1 = temp1 + 1
  133. num_index2 = all_1[temp1]
  134. num_infer2 = s[num_index2 - len(N_s[1])]
  135. num_back2 = s[num_index2 + len(N_s[1])]
  136. if isinstance(N_s[0], str):
  137. N_s[0] = int(N_s[0])
  138. if isinstance(N_s[1], str):
  139. N_s[1] = int(N_s[1])
  140. for k in range(len_keyword_item1):
  141. if C_s.find(keyword_item1[k]) != -1:
  142. if (num_back1 == '卷' or num_back1 == '部') and num_back2 == '分': # 第*卷*分
  143. volume_N = N_s[0]
  144. volume_score = N_s[1]
  145. type_score_dict_ocr['volume_N'] = volume_N
  146. type_score_dict_ocr['volume_total_score'] = volume_score
  147. type_score_dict_ocr['volume_count'] = -1
  148. type_score_dict_ocr['volume_score'] = -1
  149. break
  150. elif num_back1 == '.' and num_infer2 == '.' and num_back2 == '分': # 第卷,共*.*分
  151. volume_N = -1
  152. volume_score = N_s[0]
  153. type_score_dict_ocr['volume_N'] = volume_N
  154. type_score_dict_ocr['volume_total_score'] = volume_score
  155. type_score_dict_ocr['volume_count'] = -1
  156. type_score_dict_ocr['volume_score'] = -1
  157. break
  158. else:
  159. for l in range(len_keyword_item2):
  160. if C_s.find(keyword_item2[l]) != -1:
  161. if (num_infer1 == '题' or num_infer1 == '空') and num_back2 == '分': # 第卷,每小题*分,共*分
  162. volume_score = N_s[1]
  163. item_score = N_s[0]
  164. item_count = int(volume_score / item_score)
  165. type_score_dict_ocr['volume_N'] = -1
  166. type_score_dict_ocr['volume_total_score'] = volume_score
  167. type_score_dict_ocr['volume_count'] = item_count
  168. type_score_dict_ocr['volume_score'] = item_score
  169. break
  170. elif (num_infer2 == '题' or num_infer2 == '空') and num_back1 == '分': # 第卷,共*分 ,每小题*分
  171. volume_score = N_s[0]
  172. item_score = N_s[1]
  173. item_count = int(volume_score / item_score)
  174. type_score_dict_ocr['volume_N'] = -1
  175. type_score_dict_ocr['volume_total_score'] = volume_score
  176. type_score_dict_ocr['volume_count'] = item_count
  177. type_score_dict_ocr['volume_score'] = item_score
  178. break
  179. elif l == len(keyword_item2) - 1:
  180. for m in range(len_keyword_item3):
  181. if C_s.find(keyword_item3[l]) != -1:
  182. if num_back2 == '分': # 第卷,共*小题,共*分
  183. volume_score = N_s[1]
  184. item_count = N_s[0]
  185. item_score = volume_score / item_count
  186. type_score_dict_ocr['volume_N'] = -1
  187. type_score_dict_ocr['volume_total_score'] = volume_score
  188. type_score_dict_ocr['volume_count'] = item_count
  189. type_score_dict_ocr['volume_score'] = item_score
  190. break
  191. elif num_back1 == '分': # 第卷,共*分 ,共*小题
  192. volume_score = N_s[0]
  193. item_count = N_s[1]
  194. item_score = volume_score / item_count
  195. type_score_dict_ocr['volume_N'] = -1
  196. type_score_dict_ocr['volume_total_score'] = volume_score
  197. type_score_dict_ocr['volume_count'] = item_count
  198. type_score_dict_ocr['volume_score'] = item_score
  199. break
  200. break
  201. break
  202. elif k == len_keyword_item1 - 1:
  203. for l in range(len_keyword_item2):
  204. if C_s.find(keyword_item2[l]) != -1:
  205. for m in range(len_keyword_item3):
  206. if C_s.find(keyword_item3[l]) != -1:
  207. if num_back2 == '分': # 第卷,共*小题,每小题*分
  208. item_count = N_s[0]
  209. item_score = N_s[1]
  210. volume_score = item_score * item_count
  211. type_score_dict_ocr['volume_N'] = -1
  212. type_score_dict_ocr['volume_total_score'] = volume_score
  213. type_score_dict_ocr['volume_count'] = item_count
  214. type_score_dict_ocr['volume_score'] = item_score
  215. break
  216. elif num_back1 == '分': # 第卷,每小题*分 ,共*小题
  217. item_count = N_s[1]
  218. item_score = N_s[0]
  219. volume_score = item_count * item_score
  220. type_score_dict_ocr['volume_N'] = -1
  221. type_score_dict_ocr['volume_total_score'] = volume_score
  222. type_score_dict_ocr['volume_count'] = item_count
  223. type_score_dict_ocr['volume_score'] = item_score
  224. break
  225. elif m == len_keyword_item3 - 1:
  226. if num_back2 == '分': # 第卷,每小题*.*分
  227. volume_score = -1
  228. item_count = -1
  229. item_score = float(N_s[0] + '.' + N_s[1])
  230. type_score_dict_ocr['volume_N'] = -1
  231. type_score_dict_ocr['volume_total_score'] = volume_score
  232. type_score_dict_ocr['volume_count'] = item_count
  233. type_score_dict_ocr['volume_score'] = item_score
  234. break
  235. break
  236. break
  237. elif len(N_s) == 3:
  238. num_index1 = s.index(N_s[0])
  239. num_infer1 = s[num_index1 - len(N_s[0])]
  240. num_back1 = s[num_index1 + len(N_s[0])]
  241. all_1 = find_repeat(s, N_s[1])
  242. temp1 = 0
  243. for ii in range(len(N_s[0])):
  244. if N_s[0][ii] == N_s[1]:
  245. temp1 = temp1 + 1
  246. num_index2 = all_1[temp1]
  247. num_infer2 = s[num_index2 - len(N_s[1])]
  248. num_back2 = s[num_index2 + len(N_s[1])]
  249. all_2 = find_repeat(s, N_s[2])
  250. temp2 = 0
  251. for ii in range(len(N_s[0])):
  252. if N_s[0][ii] == N_s[2]:
  253. temp2 = temp2 + 1
  254. for jj in range(len(N_s[1])):
  255. if N_s[1][jj] == N_s[2]:
  256. temp2 = temp2 + 1
  257. num_index3 = all_2[temp2]
  258. num_infer3 = s[num_index3 - len(N_s[2])]
  259. num_back3 = s[num_index3 + len(N_s[2])]
  260. if isinstance(N_s[0], str):
  261. N_s[0] = int(N_s[0])
  262. if isinstance(N_s[1], str):
  263. N_s[1] = int(N_s[1])
  264. if isinstance(N_s[2], str):
  265. N_s[2] = int(N_s[2])
  266. for l in range(len_keyword_item3):
  267. if C_s.find(keyword_item3[l]) != -1:
  268. for m in range(len_keyword_item2):
  269. if C_s.find(keyword_item2[m]) != -1:
  270. if (num_back1 == '卷' or num_back1 == '部') and num_back3 == '分': # 第*卷,共*题,每题*分
  271. volume_N = N_s[0]
  272. item_count = N_s[1]
  273. item_score = N_s[2]
  274. volume_score = item_count * item_score
  275. type_score_dict_ocr['volume_N'] = volume_N
  276. type_score_dict_ocr['volume_total_score'] = volume_score
  277. type_score_dict_ocr['volume_count'] = item_count
  278. type_score_dict_ocr['volume_score'] = item_score
  279. break
  280. elif (num_back1 == '卷' or num_back1 == '部') and num_back2 == '分': # 第*卷,每题*分,共*题
  281. volume_N = N_s[0]
  282. item_count = N_s[2]
  283. item_score = N_s[1]
  284. volume_score = item_count * item_score
  285. type_score_dict_ocr['volume_N'] = volume_N
  286. type_score_dict_ocr['volume_total_score'] = volume_score
  287. type_score_dict_ocr['volume_count'] = item_count
  288. type_score_dict_ocr['volume_score'] = item_score
  289. break
  290. elif (num_back1 == '卷' or num_back1 == '部') and num_back2 == '分': # 第卷,每题*.*分,共*题
  291. volume_N = -1
  292. item_score = float(N_s[0] + '.' + N_s[1])
  293. item_count = N_s[2]
  294. volume_score = item_score * item_count
  295. type_score_dict_ocr['volume_N'] = volume_N
  296. type_score_dict_ocr['volume_total_score'] = volume_score
  297. type_score_dict_ocr['volume_count'] = item_count
  298. type_score_dict_ocr['volume_score'] = item_score
  299. break
  300. elif (num_back1 == '卷' or num_back1 == '部') and num_back3 == '分': # 第卷,共*题,每题*.*分
  301. volume_N = -1
  302. item_score = float(N_s[1] + '.' + N_s[2])
  303. item_count = N_s[0]
  304. volume_score = item_score * item_count
  305. type_score_dict_ocr['volume_N'] = volume_N
  306. type_score_dict_ocr['volume_total_score'] = volume_score
  307. type_score_dict_ocr['volume_count'] = item_count
  308. type_score_dict_ocr['volume_score'] = item_score
  309. break
  310. elif num_back1 == '分' and (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分': # 第卷,共*分,每题*分,共*题
  311. volume_score = N_s[0]
  312. item_count = N_s[2]
  313. item_score = N_s[1]
  314. type_score_dict_ocr['volume_N'] = -1
  315. type_score_dict_ocr['volume_total_score'] = volume_score
  316. type_score_dict_ocr['volume_count'] = item_count
  317. type_score_dict_ocr['volume_score'] = item_score
  318. break
  319. elif num_back1 == '分' and (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分': # 第卷,共*分,共*题,每题*分
  320. volume_score = N_s[0]
  321. item_count = N_s[1]
  322. item_score = N_s[2]
  323. type_score_dict_ocr['volume_N'] = -1
  324. type_score_dict_ocr['volume_total_score'] = volume_score
  325. type_score_dict_ocr['volume_count'] = item_count
  326. type_score_dict_ocr['volume_score'] = item_score
  327. break
  328. elif num_back2 == '分' and (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分': # 第卷,共*题,共*分,每题*分
  329. volume_score = N_s[1]
  330. item_count = N_s[0]
  331. item_score = N_s[2]
  332. type_score_dict_ocr['volume_N'] = -1
  333. type_score_dict_ocr['volume_total_score'] = volume_score
  334. type_score_dict_ocr['volume_count'] = item_count
  335. type_score_dict_ocr['volume_score'] = item_score
  336. break
  337. elif num_infer3 == '分' and (num_infer1 == '题' or num_infer1 == '空') and num_back1 == '分': # 第卷,每题*分,共*题,共*分
  338. volume_score = N_s[2]
  339. item_count = N_s[1]
  340. item_score = N_s[0]
  341. type_score_dict_ocr['volume_N'] = -1
  342. type_score_dict_ocr['volume_total_score'] = volume_score
  343. type_score_dict_ocr['volume_count'] = item_count
  344. type_score_dict_ocr['volume_score'] = item_score
  345. break
  346. elif num_back3 == '分' and (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分': # 第卷,共*题,每题*分,共*分
  347. volume_score = N_s[2]
  348. item_count = N_s[0]
  349. item_score = N_s[1]
  350. type_score_dict_ocr['volume_N'] = -1
  351. type_score_dict_ocr['volume_total_score'] = volume_score
  352. type_score_dict_ocr['volume_count'] = item_count
  353. type_score_dict_ocr['volume_score'] = item_score
  354. break
  355. elif num_back3 == '分' and (num_infer1 == '题' or num_infer1 == '空') and num_back1 == '分': # 第卷,每题*分,共*题,共*分
  356. volume_score = N_s[2]
  357. item_count = N_s[1]
  358. item_score = N_s[0]
  359. type_score_dict_ocr['volume_N'] = -1
  360. type_score_dict_ocr['volume_total_score'] = volume_score
  361. type_score_dict_ocr['volume_count'] = item_count
  362. type_score_dict_ocr['volume_score'] = item_score
  363. break
  364. elif m == len_keyword_item2 - 1:
  365. for n in range(len_keyword_item1):
  366. if C_s.find(keyword_item1[n]) != -1:
  367. if (num_back1 == '卷' or num_back1 == '部') and (num_back2 == '题' or num_back2 == '小') and num_back3 == '分': # 第*卷,共*题,共*分
  368. volume_N = N_s[0]
  369. volume_score = N_s[2]
  370. item_count = N_s[1]
  371. item_score = volume_score / item_count
  372. type_score_dict_ocr['volume_N'] = volume_N
  373. type_score_dict_ocr['volume_total_score'] = volume_score
  374. type_score_dict_ocr['volume_count'] = item_count
  375. type_score_dict_ocr['volume_score'] = item_score
  376. break
  377. elif (num_back1 == '卷' or num_back1 == '部') and (num_back3 == '题' or num_back3 == '小') and num_back2 == '分': # 第*卷,共*分,共*题
  378. volume_N = N_s[0]
  379. volume_score = N_s[1]
  380. item_count = N_s[2]
  381. item_score = volume_score / item_count
  382. type_score_dict_ocr['volume_N'] = volume_N
  383. type_score_dict_ocr['volume_total_score'] = volume_score
  384. type_score_dict_ocr['volume_count'] = item_count
  385. type_score_dict_ocr['volume_score'] = item_score
  386. break
  387. elif num_back1 == '.' and num_infer2 == '.' and (num_back3 == '题' or num_back3 == '小') and num_back2 == '分': # 第卷,共*.*分,共*题
  388. volume_N = -1
  389. volume_score = N_s[0]
  390. item_count = N_s[2]
  391. item_score = volume_score / item_count
  392. type_score_dict_ocr['volume_N'] = volume_N
  393. type_score_dict_ocr['volume_total_score'] = volume_score
  394. type_score_dict_ocr['volume_count'] = item_count
  395. type_score_dict_ocr['volume_score'] = item_score
  396. break
  397. elif num_back2 == '.' and num_infer3 == '.' and (num_back1 == '题' or num_back1 == '小') and num_back3 == '分': # 第卷,共*题,共*.*分
  398. volume_N = -1
  399. volume_score = N_s[1]
  400. item_count = N_s[0]
  401. item_score = volume_score / item_count
  402. type_score_dict_ocr['volume_N'] = volume_N
  403. type_score_dict_ocr['volume_total_score'] = volume_score
  404. type_score_dict_ocr['volume_count'] = item_count
  405. type_score_dict_ocr['volume_score'] = item_score
  406. break
  407. break
  408. break
  409. elif l == len_keyword_item3 - 1:
  410. for p in range(len_keyword_item1):
  411. if C_s.find(keyword_item1[p]) != -1:
  412. for q in range(len_keyword_item2):
  413. if C_s.find(keyword_item2[q]) != -1:
  414. if (num_back1 == '卷' or num_back1 == '部') and num_back2 == '分' and num_back3 == '分': # 第*卷,共*分,每题*分 / 第*卷,每题*分,共*分
  415. volume_N = int(N_s[0])
  416. if N_s[1] > N_s[2]:
  417. volume_score = N_s[1]
  418. item_score = N_s[2]
  419. item_count = int(volume_score / item_score)
  420. type_score_dict_ocr['volume_N'] = volume_N
  421. type_score_dict_ocr['volume_total_score'] = volume_score
  422. type_score_dict_ocr['volume_count'] = item_count
  423. type_score_dict_ocr['volume_score'] = item_score
  424. break
  425. else:
  426. volume_score = N_s[2]
  427. item_score = N_s[1]
  428. item_count = int(volume_score / item_score)
  429. type_score_dict_ocr['volume_N'] = volume_N
  430. type_score_dict_ocr['volume_total_score'] = volume_score
  431. type_score_dict_ocr['volume_count'] = item_count
  432. type_score_dict_ocr['volume_score'] = item_score
  433. break
  434. elif num_back1 == '.' and num_infer2 == '.' and num_back2 == '分' and num_back3 == '分': # 第卷,共*.*分,每题*分 / 第卷,每题*.*分,共*分
  435. volume_N = -1
  436. if N_s[0] > N_s[2]:
  437. volume_score = N_s[0]
  438. item_score = N_s[2]
  439. item_count = int(volume_score / item_score)
  440. type_score_dict_ocr['volume_N'] = volume_N
  441. type_score_dict_ocr['volume_total_score'] = volume_score
  442. type_score_dict_ocr['volume_count'] = item_count
  443. type_score_dict_ocr['volume_score'] = item_score
  444. break
  445. else:
  446. volume_score = N_s[2]
  447. item_score = float(N_s[0] + '.' + N_s[1])
  448. item_count = int(volume_score / item_score)
  449. type_score_dict_ocr['volume_N'] = volume_N
  450. type_score_dict_ocr['volume_total_score'] = volume_score
  451. type_score_dict_ocr['volume_count'] = item_count
  452. type_score_dict_ocr['volume_score'] = item_score
  453. break
  454. elif num_back2 == '.' and num_infer3 == '.' and num_back1 == '分' and num_back3 == '分': # 第卷,共*分,每题*.*分 / 第卷,每题*分,共*.*分
  455. volume_N = -1
  456. if N_s[0] > N_s[1]:
  457. volume_score = N_s[0]
  458. item_score = float(N_s[1] + '.' + N_s[2])
  459. item_count = int(volume_score / item_score)
  460. type_score_dict_ocr['volume_N'] = volume_N
  461. type_score_dict_ocr['volume_total_score'] = volume_score
  462. type_score_dict_ocr['volume_count'] = item_count
  463. type_score_dict_ocr['volume_score'] = item_score
  464. break
  465. else:
  466. volume_score = N_s[1]
  467. item_score = N_s[0]
  468. item_count = int(volume_score / item_score)
  469. type_score_dict_ocr['volume_N'] = volume_N
  470. type_score_dict_ocr['volume_total_score'] = volume_score
  471. type_score_dict_ocr['volume_count'] = item_count
  472. type_score_dict_ocr['volume_score'] = item_score
  473. break
  474. break
  475. break
  476. elif len(N_s) == 4:
  477. num_index1 = s.index(N_s[0])
  478. num_infer1 = s[num_index1 - len(N_s[0])]
  479. num_back1 = s[num_index1 + len(N_s[0])]
  480. all_1 = find_repeat(s, N_s[1])
  481. temp1 = 0
  482. for ii in range(len(N_s[0])):
  483. if N_s[0][ii] == N_s[1]:
  484. temp1 = temp1 + 1
  485. num_index2 = all_1[temp1]
  486. num_infer2 = s[num_index2 - len(N_s[1])]
  487. num_back2 = s[num_index2 + len(N_s[1])]
  488. all_2 = find_repeat(s, N_s[2])
  489. temp2 = 0
  490. for ii in range(len(N_s[0])):
  491. if N_s[0][ii] == N_s[2]:
  492. temp2 = temp2 + 1
  493. for jj in range(len(N_s[1])):
  494. if N_s[1][jj] == N_s[2]:
  495. temp2 = temp2 + 1
  496. num_index3 = all_2[temp2]
  497. num_infer3 = s[num_index3 - len(N_s[2])]
  498. num_back3 = s[num_index3 + len(N_s[2])]
  499. all_3 = find_repeat(s, N_s[3])
  500. temp3 = 0
  501. for ii in range(len(N_s[0])):
  502. if N_s[0][ii] == N_s[3]:
  503. temp3 = temp3 + 1
  504. for jj in range(len(N_s[1])):
  505. if N_s[1][jj] == N_s[3]:
  506. temp3 = temp3 + 1
  507. for kk in range(len(N_s[2])):
  508. if N_s[2][kk] == N_s[3]:
  509. temp3 = temp3 + 1
  510. num_index4 = all_3[temp3]
  511. num_infer4 = s[num_index4 - len(N_s[3])]
  512. num_back4 = s[num_index4 + len(N_s[3])]
  513. if isinstance(N_s[0], str):
  514. N_s[0] = int(N_s[0])
  515. if isinstance(N_s[1], str):
  516. N_s[1] = int(N_s[1])
  517. if isinstance(N_s[2], str):
  518. N_s[2] = int(N_s[2])
  519. if isinstance(N_s[3], str):
  520. N_s[3] = int(N_s[3])
  521. for l in range(len_keyword_item1):
  522. if C_s.find(keyword_item1[l]) != -1:
  523. for m in range(len_keyword_item2):
  524. if C_s.find(keyword_item2[m]) != -1:
  525. for n in range(len_keyword_item3):
  526. if C_s.find(keyword_item3[n]) != -1:
  527. if (num_back1 == '卷' or num_back1 == '部') and (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back4 == '分': # 第*卷,每题*分,共*题,共*分
  528. volume_N = N_s[0]
  529. volume_score = N_s[3]
  530. item_count = N_s[2]
  531. item_score = N_s[1]
  532. type_score_dict_ocr['volume_N'] = volume_N
  533. type_score_dict_ocr['volume_total_score'] = volume_score
  534. type_score_dict_ocr['volume_count'] = item_count
  535. type_score_dict_ocr['volume_score'] = item_score
  536. break
  537. elif (num_back1 == '卷' or num_back1 == '部') and (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分' and num_back4 == '分': # 第*卷,共*题,每题*分,共*分
  538. volume_N = N_s[0]
  539. volume_score = N_s[3]
  540. item_count = N_s[1]
  541. item_score = N_s[2]
  542. type_score_dict_ocr['volume_N'] = volume_N
  543. type_score_dict_ocr['volume_total_score'] = volume_score
  544. type_score_dict_ocr['volume_count'] = item_count
  545. type_score_dict_ocr['volume_score'] = item_score
  546. break
  547. elif (num_back1 == '卷' or num_back1 == '部') and (num_infer4 == '题' or num_infer4 == '空') and num_back4 == '分' and num_back2 == '分': # 第*卷,共*分,共*题,每题*分
  548. volume_N = N_s[0]
  549. volume_score = N_s[1]
  550. item_count = N_s[2]
  551. item_score = N_s[3]
  552. type_score_dict_ocr['volume_N'] = volume_N
  553. type_score_dict_ocr['volume_total_score'] = volume_score
  554. type_score_dict_ocr['volume_count'] = item_count
  555. type_score_dict_ocr['volume_score'] = item_score
  556. break
  557. elif (num_back1 == '卷' or num_back1 == '部') and (num_infer4 == '题' or num_infer4 == '空') and num_back4 == '分' and num_back3 == '分': # 第*卷,共*题,共*分,每题*分
  558. volume_N = N_s[0]
  559. volume_score = N_s[2]
  560. item_count = N_s[1]
  561. item_score = N_s[3]
  562. type_score_dict_ocr['volume_N'] = volume_N
  563. type_score_dict_ocr['volume_total_score'] = volume_score
  564. type_score_dict_ocr['volume_count'] = item_count
  565. type_score_dict_ocr['volume_score'] = item_score
  566. break
  567. elif (num_back1 == '卷' or num_back1 == '部') and (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分' and num_back2 == '分': # 第*卷,共*分,每题*分,共*题
  568. volume_N = N_s[0]
  569. volume_score = N_s[1]
  570. item_count = N_s[3]
  571. item_score = N_s[2]
  572. type_score_dict_ocr['volume_N'] = volume_N
  573. type_score_dict_ocr['volume_total_score'] = volume_score
  574. type_score_dict_ocr['volume_count'] = item_count
  575. type_score_dict_ocr['volume_score'] = item_score
  576. break
  577. elif (num_back1 == '卷' or num_back1 == '部') and (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back3 == '分': # 第*卷,每题*分,共*分,共*题
  578. volume_N = N_s[0]
  579. volume_score = N_s[2]
  580. item_count = N_s[3]
  581. item_score = N_s[1]
  582. type_score_dict_ocr['volume_N'] = volume_N
  583. type_score_dict_ocr['volume_total_score'] = volume_score
  584. type_score_dict_ocr['volume_count'] = item_count
  585. type_score_dict_ocr['volume_score'] = item_score
  586. break
  587. elif (num_back1 == '.' and num_infer2 == '.') and num_back2 == '分' and num_back3 == '分': # 第卷,每题*.*分,共*分,共*题/第卷,共*.*分,每题*分,共*题
  588. volume_N = -1
  589. if int(N_s[0]) > int(N_s[2]):
  590. volume_score = N_s[0]
  591. item_score = N_s[2]
  592. item_count = int(volume_score / item_score)
  593. type_score_dict_ocr['volume_N'] = volume_N
  594. type_score_dict_ocr['volume_total_score'] = volume_score
  595. type_score_dict_ocr['volume_count'] = item_count
  596. type_score_dict_ocr['volume_score'] = item_score
  597. break
  598. else:
  599. volume_score = N_s[2]
  600. item_score = float(N_s[0] + '.' + N_s[1])
  601. item_count = int(volume_score / item_score)
  602. type_score_dict_ocr['volume_N'] = volume_N
  603. type_score_dict_ocr['volume_total_score'] = volume_score
  604. type_score_dict_ocr['volume_count'] = item_count
  605. type_score_dict_ocr['volume_score'] = item_score
  606. break
  607. elif (num_back2 == '.' and num_infer3 == '.') and num_back1 == '分' and num_back3 == '分': # 第卷,每题*分,共*.*分,共*题/第卷,共*分,每题*.*分,共*题
  608. volume_N = -1
  609. if int(N_s[0]) > int(N_s[1]):
  610. volume_score = N_s[0]
  611. item_score = float(N_s[1] + '.' + N_s[2])
  612. item_count = int(volume_score / item_score)
  613. type_score_dict_ocr['volume_N'] = volume_N
  614. type_score_dict_ocr['volume_total_score'] = volume_score
  615. type_score_dict_ocr['volume_count'] = item_count
  616. type_score_dict_ocr['volume_score'] = item_score
  617. break
  618. else:
  619. volume_score = N_s[1]
  620. item_score = N_s[0]
  621. item_count = int(volume_score / item_score)
  622. type_score_dict_ocr['volume_N'] = volume_N
  623. type_score_dict_ocr['volume_total_score'] = volume_score
  624. type_score_dict_ocr['volume_count'] = item_count
  625. type_score_dict_ocr['volume_score'] = item_score
  626. break
  627. elif (num_back2 == '.' and num_infer3 == '.') and num_back3 == '分' and num_back4 == '分': # 第卷,共*题,共*.*分,每题*分/第卷,共*题,每题*.*分,共*分
  628. volume_N = -1
  629. if N_s[1] > N_s[3]:
  630. volume_score = N_s[1]
  631. item_score = N_s[3]
  632. item_count = int(volume_score / item_score)
  633. type_score_dict_ocr['volume_N'] = volume_N
  634. type_score_dict_ocr['volume_total_score'] = volume_score
  635. type_score_dict_ocr['volume_count'] = item_count
  636. type_score_dict_ocr['volume_score'] = item_score
  637. break
  638. else:
  639. volume_score = N_s[4]
  640. item_score = float(N_s[1] + '.' + N_s[2])
  641. item_count = int(volume_score / item_score)
  642. type_score_dict_ocr['volume_N'] = volume_N
  643. type_score_dict_ocr['volume_total_score'] = volume_score
  644. type_score_dict_ocr['volume_count'] = item_count
  645. type_score_dict_ocr['volume_score'] = item_score
  646. break
  647. elif (num_back3 == '.' and num_infer4 == '.') and num_back2 == '分' and num_back4 == '分': # 第卷,共*题,共*分,每题*.*分/第卷,共*题,每题*分,共*.*分
  648. volume_N = -1
  649. if int(N_s[1]) > int(N_s[2]):
  650. volume_score = N_s[1]
  651. item_score = float(N_s[2] + '.' + N_s[3])
  652. item_count = int(volume_score / item_score)
  653. type_score_dict_ocr['volume_N'] = volume_N
  654. type_score_dict_ocr['volume_total_score'] = volume_score
  655. type_score_dict_ocr['volume_count'] = item_count
  656. type_score_dict_ocr['volume_score'] = item_score
  657. break
  658. else:
  659. volume_score = N_s[2]
  660. item_score = N_s[1]
  661. item_count = int(volume_score / item_score)
  662. type_score_dict_ocr['volume_N'] = volume_N
  663. type_score_dict_ocr['volume_total_score'] = volume_score
  664. type_score_dict_ocr['volume_count'] = item_count
  665. type_score_dict_ocr['volume_score'] = item_score
  666. break
  667. elif (num_back1 == '.' and num_infer2 == '.') and num_back2 == '分' and num_back4 == '分': # 第卷,共*.*分,共*题,每题*分/第卷,每题*.*分,共*题,共*分
  668. volume_N = -1
  669. if int(N_s[0]) > int(N_s[3]):
  670. volume_score = N_s[0]
  671. item_score = N_s[3]
  672. item_count = int(volume_score / item_score)
  673. type_score_dict_ocr['volume_N'] = volume_N
  674. type_score_dict_ocr['volume_total_score'] = volume_score
  675. type_score_dict_ocr['volume_count'] = item_count
  676. type_score_dict_ocr['volume_score'] = item_score
  677. break
  678. else:
  679. volume_score = N_s[3]
  680. item_score = float(N_s[0] + '.' + N_s[1])
  681. item_count = int(volume_score / item_score)
  682. type_score_dict_ocr['volume_N'] = volume_N
  683. type_score_dict_ocr['volume_total_score'] = volume_score
  684. type_score_dict_ocr['volume_count'] = item_count
  685. type_score_dict_ocr['volume_score'] = item_score
  686. break
  687. elif (num_back3 == '.' and num_infer4 == '.') and num_back1 == '分' and num_back4 == '分': # 第卷,共*分,共*题,每题*.*分/第卷,每题*分,共*题,共*.*分
  688. volume_N = -1
  689. if int(N_s[0]) > int(N_s[2]):
  690. volume_score = N_s[0]
  691. item_score = N_s[2] + '.' + N_s[3]
  692. item_count = int(volume_score / item_score)
  693. type_score_dict_ocr['volume_N'] = volume_N
  694. type_score_dict_ocr['volume_total_score'] = volume_score
  695. type_score_dict_ocr['volume_count'] = item_count
  696. type_score_dict_ocr['volume_score'] = item_score
  697. break
  698. else:
  699. volume_score = N_s[2]
  700. item_score = N_s[0]
  701. item_count = int(volume_score / item_score)
  702. type_score_dict_ocr['volume_N'] = volume_N
  703. type_score_dict_ocr['volume_total_score'] = volume_score
  704. type_score_dict_ocr['volume_count'] = item_count
  705. type_score_dict_ocr['volume_score'] = item_score
  706. break
  707. elif n == len_keyword_item3 - 1:
  708. if (num_back1 == '卷' or num_back1 == '部') and num_back2 == '.' and num_infer3 == '.' and num_back3 == '分' and num_back4 == '分': # 第*卷,每题*.*分,共*分/第*卷,共*.*分,每题*分
  709. volume_N = int(N_s[0])
  710. if N_s[1] > N_s[3]:
  711. volume_score = N_s[1]
  712. item_score = N_s[3]
  713. item_count = int(volume_score / item_score)
  714. type_score_dict_ocr['volume_N'] = volume_N
  715. type_score_dict_ocr['volume_total_score'] = volume_score
  716. type_score_dict_ocr['volume_count'] = item_count
  717. type_score_dict_ocr['volume_score'] = item_score
  718. break
  719. else:
  720. volume_score = N_s[3]
  721. item_score = float(N_s[1] + '.' + N_s[2])
  722. item_count = int(volume_score / item_score)
  723. type_score_dict_ocr['volume_N'] = volume_N
  724. type_score_dict_ocr['volume_total_score'] = volume_score
  725. type_score_dict_ocr['volume_count'] = item_count
  726. type_score_dict_ocr['volume_score'] = item_score
  727. break
  728. elif (num_back1 == '卷' or num_back1 == '部') and num_back3 == '.' and num_infer4 == '.' and num_back2 == '分' and num_back4 == '分': # 第*卷,每题*分,共*.*分/第*卷,共*分,每题*.*分
  729. volume_N = int(N_s[0])
  730. if int(N_s[1]) > int(N_s[2]):
  731. volume_score = N_s[1]
  732. item_score = float(N_s[2] + '.' + N_s[3])
  733. item_count = int(volume_score / item_score)
  734. type_score_dict_ocr['volume_N'] = volume_N
  735. type_score_dict_ocr['volume_total_score'] = volume_score
  736. type_score_dict_ocr['volume_count'] = item_count
  737. type_score_dict_ocr['volume_score'] = item_score
  738. break
  739. else:
  740. volume_score = N_s[2]
  741. item_score = N_s[1]
  742. item_count = int(volume_score / item_score)
  743. type_score_dict_ocr['volume_N'] = volume_N
  744. type_score_dict_ocr['volume_total_score'] = volume_score
  745. type_score_dict_ocr['volume_count'] = item_count
  746. type_score_dict_ocr['volume_score'] = item_score
  747. break
  748. elif num_back1 == '.' and num_infer2 == '.' and num_back2 == '分' and num_back3 == '.' and num_infer4 == '.' and num_back4 == '分': # 第卷,每题*.*分,共*.*分/第卷,共*.*分,每题*.*分
  749. volume_N = -1
  750. if N_s[0] > N_s[2]:
  751. volume_score = float(N_s[2] + '.' + N_s[3])
  752. item_score = N_s[3]
  753. item_count = int(volume_score / item_score)
  754. type_score_dict_ocr['volume_N'] = volume_N
  755. type_score_dict_ocr['volume_total_score'] = volume_score
  756. type_score_dict_ocr['volume_count'] = item_count
  757. type_score_dict_ocr['volume_score'] = item_score
  758. break
  759. else:
  760. volume_score = N_s[3]
  761. item_score = float(N_s[1] + '.' + N_s[2])
  762. item_count = int(volume_score / item_score)
  763. type_score_dict_ocr['volume_N'] = volume_N
  764. type_score_dict_ocr['volume_total_score'] = volume_score
  765. type_score_dict_ocr['volume_count'] = item_count
  766. type_score_dict_ocr['volume_score'] = item_score
  767. break
  768. elif (num_back1 == '卷' or num_back1 == '部') and (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back3 == '分': # 第*卷,每题*分,共*分
  769. volume_N = N_s[0]
  770. volume_score = N_s[2]
  771. item_count = -1
  772. item_score = N_s[1]
  773. type_score_dict_ocr['volume_N'] = volume_N
  774. type_score_dict_ocr['volume_total_score'] = volume_score
  775. type_score_dict_ocr['volume_count'] = item_count
  776. type_score_dict_ocr['volume_score'] = item_score
  777. break
  778. elif (num_back1 == '卷' or num_back1 == '部') and (num_infer3 == '题' or num_infer3 == '空') and num_back2 == '分' and num_back3 == '分': # 第*卷,共*分,每题*分
  779. volume_N = N_s[0]
  780. volume_score = N_s[1]
  781. item_count = -1
  782. item_score = N_s[2]
  783. type_score_dict_ocr['volume_N'] = volume_N
  784. type_score_dict_ocr['volume_total_score'] = volume_score
  785. type_score_dict_ocr['volume_count'] = item_count
  786. type_score_dict_ocr['volume_score'] = item_score
  787. break
  788. break
  789. break
  790. elif len(N_s) == 5:
  791. num_index1 = s.index(N_s[0])
  792. num_infer1 = s[num_index1 - len(N_s[0])]
  793. num_back1 = s[num_index1 + len(N_s[0])]
  794. all_1 = find_repeat(s, N_s[1])
  795. temp1 = 0
  796. for ii in range(len(N_s[0])):
  797. if N_s[0][ii] == N_s[1]:
  798. temp1 = temp1 + 1
  799. num_index2 = all_1[temp1]
  800. num_infer2 = s[num_index2 - len(N_s[1])]
  801. num_back2 = s[num_index2 + len(N_s[1])]
  802. all_2 = find_repeat(s, N_s[2])
  803. temp2 = 0
  804. for ii in range(len(N_s[0])):
  805. if N_s[0][ii] == N_s[2]:
  806. temp2 = temp2 + 1
  807. for jj in range(len(N_s[1])):
  808. if N_s[1][jj] == N_s[2]:
  809. temp2 = temp2 + 1
  810. num_index3 = all_2[temp2]
  811. num_infer3 = s[num_index3 - len(N_s[2])]
  812. num_back3 = s[num_index3 + len(N_s[2])]
  813. all_3 = find_repeat(s, N_s[3])
  814. temp3 = 0
  815. for ii in range(len(N_s[0])):
  816. if N_s[0][ii] == N_s[3]:
  817. temp3 = temp3 + 1
  818. for jj in range(len(N_s[1])):
  819. if N_s[1][jj] == N_s[3]:
  820. temp3 = temp3 + 1
  821. for kk in range(len(N_s[2])):
  822. if N_s[2][kk] == N_s[3]:
  823. temp3 = temp3 + 1
  824. num_index4 = all_3[temp3]
  825. num_infer4 = s[num_index4 - len(N_s[3])]
  826. num_back4 = s[num_index4 + len(N_s[3])]
  827. all_4 = find_repeat(s, N_s[4])
  828. temp4 = 0
  829. for ii in range(len(N_s[0])):
  830. if N_s[0][ii] == N_s[4]:
  831. temp4 = temp4 + 1
  832. for jj in range(len(N_s[1])):
  833. if N_s[1][jj] == N_s[4]:
  834. temp4 = temp4 + 1
  835. for kk in range(len(N_s[2])):
  836. if N_s[2][kk] == N_s[4]:
  837. temp4 = temp4 + 1
  838. for ll in range(len(N_s[3])):
  839. if N_s[3][ll] == N_s[4]:
  840. temp4 = temp4 + 1
  841. num_index5 = all_4[temp4]
  842. num_infer5 = s[num_index5 - len(N_s[4])]
  843. num_back5 = s[num_index5 + len(N_s[4])]
  844. if isinstance(N_s[0], str):
  845. N_s[0] = int(N_s[0])
  846. if isinstance(N_s[1], str):
  847. N_s[1] = int(N_s[1])
  848. if isinstance(N_s[2], str):
  849. N_s[2] = int(N_s[2])
  850. if isinstance(N_s[3], str):
  851. N_s[3] = int(N_s[3])
  852. if isinstance(N_s[4], str):
  853. N_s[4] = int(N_s[4])
  854. for l in range(len_keyword_item1):
  855. if C_s.find(keyword_item1[l]) != -1:
  856. for m in range(len_keyword_item2):
  857. if C_s.find(keyword_item2[m]) != -1:
  858. for n in range(len_keyword_item3):
  859. if C_s.find(keyword_item3[n]) != -1:
  860. if (num_back1 == '卷' or num_back1 == '部') and (num_back2 == '.' and num_infer3 == '.') and num_back3 == '分' and num_back4 == '分': # 第*卷,每题*.*分,共*分,共*题/第卷,共*.*分,每题*分,共*题
  861. volume_N = N_s[0]
  862. if N_s[1] > N_s[3]:
  863. volume_score = N_s[1]
  864. item_score = N_s[3]
  865. item_count = int(volume_score / item_score)
  866. type_score_dict_ocr['volume_N'] = volume_N
  867. type_score_dict_ocr['volume_total_score'] = volume_score
  868. type_score_dict_ocr['volume_count'] = item_count
  869. type_score_dict_ocr['volume_score'] = item_score
  870. break
  871. else:
  872. volume_score = N_s[3]
  873. item_score = float(N_s[1] + '.' + N_s[2])
  874. item_count = int(volume_score / item_score)
  875. type_score_dict_ocr['volume_N'] = volume_N
  876. type_score_dict_ocr['volume_total_score'] = volume_score
  877. type_score_dict_ocr['volume_count'] = item_count
  878. type_score_dict_ocr['volume_score'] = item_score
  879. break
  880. elif (num_back1 == '卷' or num_back1 == '部') and (num_back3 == '.' and num_infer4 == '.') and num_back2 == '分' and num_back4 == '分': # 第*卷,每题*分,共*.*分,共*题/第卷,共*分,每题*.*分,共*题
  881. volume_N = N_s[0]
  882. if N_s[1] > N_s[2]:
  883. volume_score = N_s[1]
  884. item_score = float(N_s[2] + '.' + N_s[3])
  885. item_count = int(volume_score / item_score)
  886. type_score_dict_ocr['volume_N'] = volume_N
  887. type_score_dict_ocr['volume_total_score'] = volume_score
  888. type_score_dict_ocr['volume_count'] = item_count
  889. type_score_dict_ocr['volume_score'] = item_score
  890. break
  891. else:
  892. volume_score = N_s[2]
  893. item_score = N_s[1]
  894. item_count = int(volume_score / item_score)
  895. type_score_dict_ocr['volume_N'] = volume_N
  896. type_score_dict_ocr['volume_total_score'] = volume_score
  897. type_score_dict_ocr['volume_count'] = item_count
  898. type_score_dict_ocr['volume_score'] = item_score
  899. break
  900. elif (num_back1 == '卷' or num_back1 == '部') and (num_back3 == '.' and num_infer4 == '.') and num_back4 == '分' and num_back5 == '分': # 第卷,共*题,共*.*分,每题*分/第卷,共*题,每题*.*分,共*分
  901. volume_N = N_s[0]
  902. if N_s[2] > N_s[4]:
  903. volume_score = N_s[2]
  904. item_score = N_s[4]
  905. item_count = int(volume_score / item_score)
  906. type_score_dict_ocr['volume_N'] = volume_N
  907. type_score_dict_ocr['volume_total_score'] = volume_score
  908. type_score_dict_ocr['volume_count'] = item_count
  909. type_score_dict_ocr['volume_score'] = item_score
  910. break
  911. else:
  912. volume_score = N_s[4]
  913. item_score = float(N_s[2] + '.' + N_s[3])
  914. item_count = int(volume_score / item_score)
  915. type_score_dict_ocr['volume_N'] = volume_N
  916. type_score_dict_ocr['volume_total_score'] = volume_score
  917. type_score_dict_ocr['volume_count'] = item_count
  918. type_score_dict_ocr['volume_score'] = item_score
  919. break
  920. elif (num_back1 == '卷' or num_back1 == '部') and (num_back4 == '.' and num_infer5 == '.') and num_back3 == '分' and num_back5 == '分': # 第*卷,共*题,共*分,每题*.*分/第卷,共*题,每题*分,共*.*分
  921. volume_N = N_s[0]
  922. if N_s[2] > N_s[3]:
  923. volume_score = N_s[2]
  924. item_score = float(N_s[3] + '.' + N_s[4])
  925. item_count = int(volume_score / item_score)
  926. type_score_dict_ocr['volume_N'] = volume_N
  927. type_score_dict_ocr['volume_total_score'] = volume_score
  928. type_score_dict_ocr['volume_count'] = item_count
  929. type_score_dict_ocr['volume_score'] = item_score
  930. break
  931. else:
  932. volume_score = N_s[3]
  933. item_score = N_s[2]
  934. item_count = int(volume_score / item_score)
  935. type_score_dict_ocr['volume_N'] = volume_N
  936. type_score_dict_ocr['volume_total_score'] = volume_score
  937. type_score_dict_ocr['volume_count'] = item_count
  938. type_score_dict_ocr['volume_score'] = item_score
  939. break
  940. elif (num_back1 == '卷' or num_back1 == '部') and (num_back2 == '.' and num_infer3 == '.') and num_back3 == '分' and num_back5 == '分': # 第*卷,共*.*分,共*题,每题*分/第*卷,每题*.*分,共*题,共*分
  941. volume_N = N_s[0]
  942. if N_s[1] > N_s[4]:
  943. volume_score = N_s[1]
  944. item_score = N_s[4]
  945. item_count = int(volume_score / item_score)
  946. type_score_dict_ocr['volume_N'] = volume_N
  947. type_score_dict_ocr['volume_total_score'] = volume_score
  948. type_score_dict_ocr['volume_count'] = item_count
  949. type_score_dict_ocr['volume_score'] = item_score
  950. break
  951. else:
  952. volume_score = N_s[4]
  953. item_score = float(N_s[1] + '.' + N_s[2])
  954. item_count = int(volume_score / item_score)
  955. type_score_dict_ocr['volume_N'] = volume_N
  956. type_score_dict_ocr['volume_total_score'] = volume_score
  957. type_score_dict_ocr['volume_count'] = item_count
  958. type_score_dict_ocr['volume_score'] = item_score
  959. break
  960. elif (num_back1 == '卷' or num_back1 == '部') and (num_back4 == '.' and num_infer5 == '.') and num_back2 == '分' and num_back5 == '分': # 第*卷,共*分,共*题,每题*.*分/第卷,每题*分,共*题,共*.*分
  961. volume_N = N_s[0]
  962. if N_s[1] > N_s[3]:
  963. volume_score = N_s[0]
  964. item_score = float(N_s[4] + '.' + N_s[4])
  965. item_count = int(volume_score / item_score)
  966. type_score_dict_ocr['volume_N'] = volume_N
  967. type_score_dict_ocr['volume_total_score'] = volume_score
  968. type_score_dict_ocr['volume_count'] = item_count
  969. type_score_dict_ocr['volume_score'] = item_score
  970. break
  971. else:
  972. volume_score = N_s[3]
  973. item_score = N_s[1]
  974. item_count = int(volume_score / item_score)
  975. type_score_dict_ocr['volume_N'] = volume_N
  976. type_score_dict_ocr['volume_total_score'] = volume_score
  977. type_score_dict_ocr['volume_count'] = item_count
  978. type_score_dict_ocr['volume_score'] = item_score
  979. break
  980. break
  981. break
  982. if 'volume_N' not in type_score_dict_ocr.keys():
  983. all_structure = {'volume_structure': -1,
  984. 'Score_structure': -1}
  985. break
  986. else:
  987. for i in range(len_keyword_type):
  988. if C_s.find(keyword_type[i]) != -1 and C_s.find('非') != -1:
  989. type_score_dict_ocr['keyword_type'] = keyword_type[1]
  990. break
  991. elif C_s.find(keyword_type[0]) != -1:
  992. type_score_dict_ocr['keyword_type'] = keyword_type[0]
  993. Score_structure_item = type_score_dict_ocr
  994. Score_structure.append(Score_structure_item)
  995. break
  996. elif C_s.find(keyword_type[i]) != -1:
  997. type_score_dict_ocr['keyword_type'] = keyword_type[i]
  998. break
  999. elif i == len_keyword_type - 1:
  1000. type_score_dict_ocr['keyword_type'] = keyword_type[0]
  1001. Score_structure_item = type_score_dict_ocr
  1002. Score_structure.append(Score_structure_item)
  1003. break
  1004. volume_structure_item = type_score_dict_ocr
  1005. volume_structure.append(volume_structure_item)
  1006. if Score_structure == []:
  1007. all_structure = {'volume_structure': volume_structure,
  1008. 'Score_structure': -1}
  1009. else:
  1010. all_structure = {'volume_structure': volume_structure,
  1011. 'Score_structure': Score_structure}
  1012. break
  1013. elif iiii == len(keyword_volume) - 1:
  1014. '''
  1015. 对应试卷中不存在分卷信息的情况,根据包含数字的个数分为4类,暂定包含信息的有效数字个数小于4,并处理小题分数和总分可能包含小数点的情况
  1016. 暂定小题个数不包含小数
  1017. 暂定总分数中不存在有意义的小数位
  1018. '''
  1019. for xxx in range(len_keyword_type):
  1020. if C_s.find(keyword_type[xxx]) != -1:
  1021. for x in range(len_keyword_item1):
  1022. if C_s.find(keyword_item1[x]) != -1:
  1023. if len(N_s) == 1:
  1024. num_index = s.index(N_s[0])
  1025. num_infer = s[num_index - len(N_s[0])]
  1026. num_back = s[num_index + len(N_s[0])]
  1027. if isinstance(N_s[0], str):
  1028. N_s[0] = int(N_s[0])
  1029. if num_back == '分': # 选择题/主观题,共*分
  1030. item_total_score = N_s[0]
  1031. type_score_dict_ocr['volume_N'] = -1
  1032. type_score_dict_ocr['volume_total_score'] = int(item_total_score)
  1033. type_score_dict_ocr['volume_count'] = -1
  1034. type_score_dict_ocr['volume_score'] = -1
  1035. break
  1036. elif len(N_s) == 2:
  1037. num_index1 = s.index(N_s[0])
  1038. num_infer1 = s[num_index1 - len(N_s[0])]
  1039. num_back1 = s[num_index1 + len(N_s[0])]
  1040. all_1 = find_repeat(s, N_s[1])
  1041. temp1 = 0
  1042. for ii in range(len(N_s[0])):
  1043. if N_s[0][ii] == N_s[1]:
  1044. temp1 = temp1 + 1
  1045. num_index2 = all_1[temp1]
  1046. num_infer2 = s[num_index2 - len(N_s[1])]
  1047. num_back2 = s[num_index2 + len(N_s[1])]
  1048. if isinstance(N_s[0], str):
  1049. N_s[0] = int(N_s[0])
  1050. if isinstance(N_s[1], str):
  1051. N_s[1] = int(N_s[1])
  1052. for y in range(len_keyword_item2):
  1053. if C_s.find(keyword_item2[y]) != -1:
  1054. if num_back1 == '分' and (num_infer2 == '题' or num_infer2 == '空'): # 选择题/主观题/客观题,共*分,每题*分
  1055. item_total_score = int(N_s[0])
  1056. item_count = int(N_s[0] / N_s[1])
  1057. item_score = N_s[1]
  1058. type_score_dict_ocr['volume_N'] = -1
  1059. type_score_dict_ocr['volume_total_score'] = item_total_score
  1060. type_score_dict_ocr['volume_count'] = item_count
  1061. type_score_dict_ocr['volume_score'] = item_score
  1062. break
  1063. elif ( num_infer1 == '题' or num_infer1 == '空') and num_back2 == '分': # 选择题/主观题,每题*分,共*分
  1064. item_total_score = N_s[1]
  1065. item_count = int(N_s[1] / N_s[0])
  1066. item_score = N_s[0]
  1067. type_score_dict_ocr['volume_N'] = -1
  1068. type_score_dict_ocr['volume_total_score'] = item_total_score
  1069. type_score_dict_ocr['volume_count'] = item_count
  1070. type_score_dict_ocr['volume_score'] = item_score
  1071. break
  1072. elif y == len_keyword_item2 - 1:
  1073. for u in range(len_keyword_item3):
  1074. if C_s.find(keyword_item3[u]) != -1:
  1075. if num_back1 == '分': # 选择题/主观题,共*分,共*题
  1076. item_total_score = N_s[0]
  1077. item_count = N_s[1]
  1078. item_score = N_s[0] / N_s[1]
  1079. type_score_dict_ocr['volume_N'] = -1
  1080. type_score_dict_ocr['volume_total_score'] = item_total_score
  1081. type_score_dict_ocr['volume_count'] = item_count
  1082. type_score_dict_ocr['volume_score'] = item_score
  1083. break
  1084. elif num_back2 == '分': # 选择题/主观题,共*题,共*分
  1085. item_total_score = N_s[1]
  1086. item_count = N_s[0]
  1087. item_score = N_s[1] / N_s[0]
  1088. type_score_dict_ocr['volume_N'] = -1
  1089. type_score_dict_ocr['volume_total_score'] = item_total_score
  1090. type_score_dict_ocr['volume_count'] = item_count
  1091. type_score_dict_ocr['volume_score'] = item_score
  1092. break
  1093. elif u == len_keyword_item3 - 1:
  1094. if num_back1 == '.' and num_infer2 == '.' and num_back2 == '分': # *.*分
  1095. item_N = -1
  1096. item_total_score = N_s[0]
  1097. type_score_dict_ocr['volume_N'] = item_N
  1098. type_score_dict_ocr['volume_total_score'] = item_total_score
  1099. type_score_dict_ocr['volume_count'] = -1
  1100. type_score_dict_ocr['volume_score'] = -1
  1101. break
  1102. elif num_back2 == '分': # *,*分
  1103. item_N = N_s[0]
  1104. item_total_score = int(N_s[1])
  1105. type_score_dict_ocr['volume_N'] = item_N
  1106. type_score_dict_ocr['volume_total_score'] = item_total_score
  1107. type_score_dict_ocr['volume_count'] = -1
  1108. type_score_dict_ocr['volume_score'] = -1
  1109. break
  1110. break
  1111. break
  1112. elif len(N_s) == 3:
  1113. num_index1 = s.index(N_s[0])
  1114. num_infer1 = s[num_index1 - len(N_s[0])]
  1115. num_back1 = s[num_index1 + len(N_s[0])]
  1116. all_1 = find_repeat(s, N_s[1])
  1117. temp1 = 0
  1118. for ii in range(len(N_s[0])):
  1119. if N_s[0][ii] == N_s[1]:
  1120. temp1 = temp1 + 1
  1121. num_index2 = all_1[temp1]
  1122. num_infer2 = s[num_index2 - len(N_s[1])]
  1123. num_back2 = s[num_index2 + len(N_s[1])]
  1124. all_2 = find_repeat(s, N_s[2])
  1125. temp2 = 0
  1126. for ii in range(len(N_s[0])):
  1127. if N_s[0][ii] == N_s[2]:
  1128. temp2 = temp2 + 1
  1129. for jj in range(len(N_s[1])):
  1130. if N_s[1][jj] == N_s[2]:
  1131. temp2 = temp2 + 1
  1132. num_index3 = all_2[temp2]
  1133. num_infer3 = s[num_index3 - len(N_s[2])]
  1134. num_back3 = s[num_index3 + len(N_s[2])]
  1135. if isinstance(N_s[0], str):
  1136. N_s[0] = int(N_s[0])
  1137. if isinstance(N_s[1], str):
  1138. N_s[1] = int(N_s[1])
  1139. if isinstance(N_s[2], str):
  1140. N_s[2] = int(N_s[2])
  1141. for v in range(len_keyword_item2):
  1142. if C_s.find(keyword_item2[v]) != -1:
  1143. for w in range(len_keyword_item3):
  1144. if C_s.find(keyword_item3[w]) != -1:
  1145. if (num_infer1 == '题' or num_infer1 == '空') and num_back1 == '分' and num_back3 == '分': # 每题*分,共*题,共*分
  1146. item_total_score = N_s[2]
  1147. item_count = N_s[1]
  1148. item_score = N_s[0]
  1149. if item_total_score < item_count * item_score:
  1150. item_total_score = item_count * item_score
  1151. type_score_dict_ocr['volume_N'] = -1
  1152. type_score_dict_ocr['volume_total_score'] = item_total_score
  1153. type_score_dict_ocr['volume_count'] = item_count
  1154. type_score_dict_ocr['volume_score'] = item_score
  1155. break
  1156. elif (num_infer1 == '题' or num_infer1 == '空') and num_back1 == '分' and num_back2 == '分': # 每题*分,共*分,共*题
  1157. item_total_score = N_s[1]
  1158. item_count = N_s[2]
  1159. item_score = N_s[0]
  1160. if item_total_score < item_count * item_score:
  1161. item_total_score = item_count * item_score
  1162. type_score_dict_ocr['volume_N'] = -1
  1163. type_score_dict_ocr['volume_total_score'] = item_total_score
  1164. type_score_dict_ocr['volume_count'] = item_count
  1165. type_score_dict_ocr['volume_score'] = item_score
  1166. break
  1167. elif (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back3 == '分': # 共*题,每题*分,共*分
  1168. item_total_score = N_s[2]
  1169. item_count = N_s[0]
  1170. item_score = N_s[1]
  1171. if item_total_score < item_count * item_score:
  1172. item_total_score = item_count * item_score
  1173. type_score_dict_ocr['volume_N'] = -1
  1174. type_score_dict_ocr['volume_total_score'] = item_total_score
  1175. type_score_dict_ocr['volume_count'] = item_count
  1176. type_score_dict_ocr['volume_score'] = item_score
  1177. break
  1178. elif (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back1 == '分': # 共*分,每题*分,共*题
  1179. item_total_score = N_s[0]
  1180. item_count = N_s[2]
  1181. item_score = N_s[1]
  1182. if item_total_score < item_count * item_score:
  1183. item_total_score = item_count * item_score
  1184. type_score_dict_ocr['volume_N'] = -1
  1185. type_score_dict_ocr['volume_total_score'] = item_total_score
  1186. type_score_dict_ocr['volume_count'] = item_count
  1187. type_score_dict_ocr['volume_score'] = item_score
  1188. break
  1189. elif (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分' and num_back2 == '分': # 共*题,共*分,每题*分
  1190. item_total_score = N_s[1]
  1191. item_count = N_s[0]
  1192. item_score = N_s[2]
  1193. if item_total_score < item_count * item_score:
  1194. item_total_score = item_count * item_score
  1195. type_score_dict_ocr['volume_N'] = -1
  1196. type_score_dict_ocr['volume_total_score'] = item_total_score
  1197. type_score_dict_ocr['volume_count'] = item_count
  1198. type_score_dict_ocr['volume_score'] = item_score
  1199. break
  1200. elif (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分' and num_back1 == '分': # 共*分,共*题, 每题*分
  1201. item_total_score = N_s[0]
  1202. item_count = N_s[1]
  1203. item_score = N_s[2]
  1204. if item_total_score < item_count * item_score:
  1205. item_total_score = item_count * item_score
  1206. type_score_dict_ocr['volume_N'] = -1
  1207. type_score_dict_ocr['volume_total_score'] = item_total_score
  1208. type_score_dict_ocr['volume_count'] = item_count
  1209. type_score_dict_ocr['volume_score'] = item_score
  1210. break
  1211. elif w == len_keyword_item3 - 1:
  1212. if num_back1 != '.' and num_back2 == '分' and (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分': # *,共*分,每题*分
  1213. item_N = N_s[0]
  1214. item_total_score = N_s[1]
  1215. item_count = int(N_s[1] / N_s[2])
  1216. item_score = N_s[2]
  1217. type_score_dict_ocr['volume_N'] = item_N
  1218. type_score_dict_ocr['volume_total_score'] = item_total_score
  1219. type_score_dict_ocr['volume_count'] = item_count
  1220. type_score_dict_ocr['volume_score'] = item_score
  1221. break
  1222. elif num_back1 != '.' and num_back3 == '分' and (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分': # *,每题*分,共*分,
  1223. item_N = N_s[0]
  1224. item_total_score = N_s[2]
  1225. item_count = int(N_s[2] / N_s[1])
  1226. item_score = N_s[1]
  1227. type_score_dict_ocr['volume_N'] = item_N
  1228. type_score_dict_ocr['volume_total_score'] = item_total_score
  1229. type_score_dict_ocr['volume_count'] = item_count
  1230. type_score_dict_ocr['volume_score'] = item_score
  1231. break
  1232. elif num_back1 == '.' and num_infer2 == '.' and num_back3 == '分' and num_back2 == '分': # 每题*.*分,共*分/共*.*分,每题*分
  1233. item_N = -1
  1234. if int(N_s[0]) > int(N_s[2]):
  1235. item_total_score = N_s[0]
  1236. item_score = N_s[2]
  1237. item_count = int(item_total_score/item_score)
  1238. else:
  1239. item_total_score = N_s[2]
  1240. item_score = float(N_s[0]+'.'+N_s[1])
  1241. item_count = int(item_total_score / item_score)
  1242. type_score_dict_ocr['volume_N'] = item_N
  1243. type_score_dict_ocr['volume_total_score'] = item_total_score
  1244. type_score_dict_ocr['volume_count'] = item_count
  1245. type_score_dict_ocr['volume_score'] = item_score
  1246. break
  1247. elif num_back2 == '.' and num_infer3 == '.' and num_back1 == '分' and num_back3 == '分': # 每题*分,共*.*分/共*分,每题*.*分
  1248. item_N = -1
  1249. if int(N_s[0]) > int(N_s[1]):
  1250. item_total_score = N_s[0]
  1251. item_score = float(N_s[1]+'.'+N_s[2])
  1252. item_count = int(item_total_score/item_score)
  1253. else:
  1254. item_total_score = N_s[1]
  1255. item_score = N_s[0]
  1256. item_count = int(item_total_score / item_score)
  1257. type_score_dict_ocr['volume_N'] = item_N
  1258. type_score_dict_ocr['volume_total_score'] = item_total_score
  1259. type_score_dict_ocr['volume_count'] = item_count
  1260. type_score_dict_ocr['volume_score'] = item_score
  1261. break
  1262. break
  1263. elif v == len_keyword_item2 - 1:
  1264. for w in range(len_keyword_item3):
  1265. if C_s.find(keyword_item3[w]) != -1:
  1266. if num_back3 == '分' and num_infer3 =='.' and num_back2 =='.': # *小题,共*.*分,
  1267. item_N = -1
  1268. item_total_score = N_s[1]
  1269. item_count = N_s[0]
  1270. item_score = N_s[1]/N_s[0]
  1271. type_score_dict_ocr['volume_N'] = item_N
  1272. type_score_dict_ocr['volume_total_score'] = item_total_score
  1273. type_score_dict_ocr['volume_count'] = item_count
  1274. type_score_dict_ocr['volume_score'] = item_score
  1275. break
  1276. elif num_back2 == '分' and num_infer2 =='.'and num_back1 =='.': # 共*.*分,*小题
  1277. item_N = -1
  1278. item_total_score = N_s[0]
  1279. item_count = N_s[2]
  1280. item_score = N_s[0]/N_s[2]
  1281. type_score_dict_ocr['volume_N'] = item_N
  1282. type_score_dict_ocr['volume_total_score'] = item_total_score
  1283. type_score_dict_ocr['volume_count'] = item_count
  1284. type_score_dict_ocr['volume_score'] = item_score
  1285. break
  1286. elif num_back3 == '分' and num_infer3 !='.': # *,*小题,共*分,
  1287. item_N = N_s[0]
  1288. item_total_score = N_s[2]
  1289. item_count = N_s[1]
  1290. item_score = N_s[2]/N_s[1]
  1291. type_score_dict_ocr['volume_N'] = item_N
  1292. type_score_dict_ocr['volume_total_score'] = item_total_score
  1293. type_score_dict_ocr['volume_count'] = item_count
  1294. type_score_dict_ocr['volume_score'] = item_score
  1295. break
  1296. elif num_back2 == '分' and num_infer2 !='.': # *,共*分,共*小题
  1297. item_N = N_s[0]
  1298. item_total_score = N_s[1]
  1299. item_count = N_s[2]
  1300. item_score = N_s[1] / N_s[2]
  1301. type_score_dict_ocr['volume_N'] = item_N
  1302. type_score_dict_ocr['volume_total_score'] = item_total_score
  1303. type_score_dict_ocr['volume_count'] = item_count
  1304. type_score_dict_ocr['volume_score'] = item_score
  1305. break
  1306. elif w == len_keyword_item3-1:
  1307. if num_back3 == '分' and num_infer3 =='.' and num_back2 =='.': # *,共*.*分,
  1308. item_N = N_s[0]
  1309. item_total_score = N_s[1]
  1310. item_count = -1
  1311. item_score = -1
  1312. type_score_dict_ocr['volume_N'] = item_N
  1313. type_score_dict_ocr['volume_total_score'] = item_total_score
  1314. type_score_dict_ocr['volume_count'] = item_count
  1315. type_score_dict_ocr['volume_score'] = item_score
  1316. break
  1317. elif num_back3 == '分':
  1318. item_total_score = N_s[1]
  1319. item_N = -1
  1320. item_count = -1
  1321. item_score = -1
  1322. type_score_dict_ocr['volume_N'] = item_N
  1323. type_score_dict_ocr['volume_total_score'] = item_total_score
  1324. type_score_dict_ocr['volume_count'] = item_count
  1325. type_score_dict_ocr['volume_score'] = item_score
  1326. break
  1327. break
  1328. break
  1329. elif len(N_s) == 4:
  1330. num_index1 = s.index(N_s[0])
  1331. num_infer1 = s[num_index1 - len(N_s[0])]
  1332. num_back1 = s[num_index1 + len(N_s[0])]
  1333. all_1 = find_repeat(s, N_s[1])
  1334. temp1 = 0
  1335. for ii in range(len(N_s[0])):
  1336. if N_s[0][ii] == N_s[1]:
  1337. temp1 = temp1 + 1
  1338. num_index2 = all_1[temp1]
  1339. num_infer2 = s[num_index2 - len(N_s[1])]
  1340. num_back2 = s[num_index2 + len(N_s[1])]
  1341. all_2 = find_repeat(s, N_s[2])
  1342. temp2 = 0
  1343. for ii in range(len(N_s[0])):
  1344. if N_s[0][ii] == N_s[2]:
  1345. temp2 = temp2 + 1
  1346. for jj in range(len(N_s[1])):
  1347. if N_s[1][jj] == N_s[2]:
  1348. temp2 = temp2 + 1
  1349. num_index3 = all_2[temp2]
  1350. num_infer3 = s[num_index3 - len(N_s[2])]
  1351. num_back3 = s[num_index3 + len(N_s[2])]
  1352. all_3 = find_repeat(s, N_s[3])
  1353. temp3 = 0
  1354. for ii in range(len(N_s[0])):
  1355. if N_s[0][ii] == N_s[3]:
  1356. temp3 = temp3 + 1
  1357. for jj in range(len(N_s[1])):
  1358. if N_s[1][jj] == N_s[3]:
  1359. temp3 = temp3 + 1
  1360. for kk in range(len(N_s[2])):
  1361. if N_s[2][kk] == N_s[3]:
  1362. temp3 = temp3 + 1
  1363. num_index4 = all_3[temp3]
  1364. num_infer4 = s[num_index4 - len(N_s[3])]
  1365. num_back4 = s[num_index4 + len(N_s[3])]
  1366. if isinstance(N_s[0], str):
  1367. N_s[0] = int(N_s[0])
  1368. if isinstance(N_s[1], str):
  1369. N_s[1] = int(N_s[1])
  1370. if isinstance(N_s[2], str):
  1371. N_s[2] = int(N_s[2])
  1372. if isinstance(N_s[3], str):
  1373. N_s[3] = int(N_s[3])
  1374. for y in range(len_keyword_item1):
  1375. if C_s.find(keyword_item1[y]) != -1:
  1376. for z in range(len_keyword_item2):
  1377. if C_s.find(keyword_item2[z]) != -1:
  1378. for u in range(len_keyword_item3):
  1379. if C_s.find(keyword_item3[u]) != -1:
  1380. if (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back4 == '分': # *,每题*分,共*题,共*分
  1381. item_N = N_s[0]
  1382. item_total_score = N_s[3]
  1383. item_count = N_s[2]
  1384. item_score = N_s[1]
  1385. type_score_dict_ocr['volume_N'] = item_N
  1386. type_score_dict_ocr[
  1387. 'volume_total_score'] = item_total_score
  1388. type_score_dict_ocr['volume_count'] = item_count
  1389. type_score_dict_ocr['volume_score'] = item_score
  1390. break
  1391. elif (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back3 == '分': # *,每题*分,共*分,共*题
  1392. item_N = N_s[0]
  1393. item_total_score = N_s[2]
  1394. item_count = N_s[3]
  1395. item_score = N_s[1]
  1396. type_score_dict_ocr['volume_N'] = item_N
  1397. if item_total_score < item_count * item_score:
  1398. item_total_score = item_count * item_score
  1399. type_score_dict_ocr[
  1400. 'volume_total_score'] = item_total_score
  1401. type_score_dict_ocr['volume_count'] = item_count
  1402. type_score_dict_ocr['volume_score'] = item_score
  1403. break
  1404. elif (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分' and num_back4 == '分': # *,共*题,每题*分,共*分
  1405. item_N = N_s[0]
  1406. item_total_score = N_s[3]
  1407. item_count = N_s[1]
  1408. item_score = N_s[2]
  1409. if item_total_score < item_count * item_score:
  1410. item_total_score = item_count * item_score
  1411. type_score_dict_ocr['volume_N'] = item_N
  1412. type_score_dict_ocr[
  1413. 'volume_total_score'] = item_total_score
  1414. type_score_dict_ocr['volume_count'] = item_count
  1415. type_score_dict_ocr['volume_score'] = item_score
  1416. break
  1417. elif (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分' and num_back2 == '分': # *,共*分,每题*分,共*题
  1418. item_N = N_s[0]
  1419. item_total_score = N_s[1]
  1420. item_count = N_s[3]
  1421. item_score = N_s[2]
  1422. type_score_dict_ocr['volume_N'] = item_N
  1423. type_score_dict_ocr[
  1424. 'volume_total_score'] = item_total_score
  1425. type_score_dict_ocr['volume_count'] = item_count
  1426. type_score_dict_ocr['volume_score'] = item_score
  1427. break
  1428. elif (num_infer4 == '题' or num_infer4 == '空') and num_back4 == '分' and num_back3 == '分': # *,共*题,共*分,每题*分
  1429. item_N = N_s[0]
  1430. item_total_score = N_s[2]
  1431. item_count = N_s[1]
  1432. item_score = N_s[3]
  1433. type_score_dict_ocr['volume_N'] = item_N
  1434. if item_total_score < item_count * item_score:
  1435. item_total_score = item_count * item_score
  1436. type_score_dict_ocr[
  1437. 'volume_total_score'] = item_total_score
  1438. type_score_dict_ocr['volume_count'] = item_count
  1439. type_score_dict_ocr['volume_score'] = item_score
  1440. break
  1441. elif (num_infer4 == '题' or num_infer4 == '空') and num_back4 == '分' and num_back2 == '分': # *,共*分,共*题, 每题*分
  1442. item_N = N_s[0]
  1443. item_total_score = N_s[1]
  1444. item_count = N_s[2]
  1445. item_score = N_s[3]
  1446. type_score_dict_ocr['item_N'] = item_N
  1447. if item_total_score < item_count * item_score:
  1448. item_total_score = item_count * item_score
  1449. type_score_dict_ocr[
  1450. 'item_total_score'] = item_total_score
  1451. type_score_dict_ocr['item_count'] = item_count
  1452. type_score_dict_ocr['item_score'] = item_score
  1453. break
  1454. elif num_back1== '.' and num_infer2== '.' and num_back2 == '分'and num_back4 == '分' : # 共*.*分,共*题, 每题*分/每题*.*分,共*题,共*分
  1455. item_N = -1
  1456. if N_s[0] > N_s[3]:
  1457. item_total_score = N_s[0]
  1458. item_score = N_s[3]
  1459. item_count = int(item_total_score / item_score)
  1460. else:
  1461. item_total_score = N_s[3]
  1462. item_score = float(N_s[0] + '.' + N_s[1])
  1463. item_count = int(item_total_score / item_score)
  1464. type_score_dict_ocr['volume_N'] = item_N
  1465. type_score_dict_ocr[ 'item_total_score'] = item_total_score
  1466. type_score_dict_ocr['item_count'] = item_count
  1467. type_score_dict_ocr['item_score'] = item_score
  1468. break
  1469. elif num_back3== '.' and num_infer4== '.' and num_back1 == '分'and num_back4 == '分' : # 共*分,共*题, 每题*.*分/每题*分,共*题,共*.*分
  1470. item_N = -1
  1471. if N_s[0] > N_s[2]:
  1472. item_total_score = N_s[0]
  1473. item_score = float(N_s[2] + '.' + N_s[3])
  1474. item_count = int(item_total_score / item_score)
  1475. else:
  1476. item_total_score = N_s[2]
  1477. item_score = N_s[0]
  1478. item_count = int(item_total_score / item_score)
  1479. type_score_dict_ocr['volume_N'] = item_N
  1480. type_score_dict_ocr[ 'item_total_score'] = item_total_score
  1481. type_score_dict_ocr['item_count'] = item_count
  1482. type_score_dict_ocr['item_score'] = item_score
  1483. break
  1484. elif num_back2== '.' and num_infer3== '.' and num_back3 == '分'and num_back4 == '分' : # 共*题,共*.*分,每题*分/共*题,每题*.*分,共*分
  1485. item_N = -1
  1486. if N_s[1] > N_s[3]:
  1487. item_total_score = N_s[1]
  1488. item_score = N_s[3]
  1489. item_count = int(item_total_score / item_score)
  1490. else:
  1491. item_total_score = N_s[3]
  1492. item_score = float(N_s[1] + '.' + N_s[2])
  1493. item_count = int(item_total_score / item_score)
  1494. type_score_dict_ocr['volume_N'] = item_N
  1495. type_score_dict_ocr['volume_total_score'] = item_total_score
  1496. type_score_dict_ocr['volume_count'] = item_count
  1497. type_score_dict_ocr['volume_score'] = item_score
  1498. break
  1499. elif num_back3== '.' and num_infer4== '.' and num_back4 == '分'and num_back2 == '分' : # 共*题,共*分,每题*.*分/共*题,每题*分,共*.*分
  1500. item_N = -1
  1501. if N_s[1] > N_s[2]:
  1502. item_total_score = N_s[1]
  1503. item_score = float(N_s[2] + '.' + N_s[3])
  1504. item_count = int(item_total_score / item_score)
  1505. else:
  1506. item_total_score = N_s[2]
  1507. item_score = N_s[1]
  1508. item_count = int(item_total_score / item_score)
  1509. type_score_dict_ocr['volume_N'] = item_N
  1510. type_score_dict_ocr['volume_total_score'] = item_total_score
  1511. type_score_dict_ocr['volume_count'] = item_count
  1512. type_score_dict_ocr['volume_score'] = item_score
  1513. break
  1514. elif num_back1== '.' and num_infer2== '.' and num_back2 == '分'and num_back3 == '分' : # 每题*.*分,共*分,共*题/共*.*分,每题*分,共*题
  1515. item_N = -1
  1516. if N_s[0] > N_s[2]:
  1517. item_total_score = N_s[0]
  1518. item_score = N_s[2]
  1519. item_count = int(item_total_score / item_score)
  1520. else:
  1521. item_total_score = N_s[2]
  1522. item_score = float(N_s[0] + '.' + N_s[1])
  1523. item_count = int(item_total_score / item_score)
  1524. type_score_dict_ocr['volume_N'] = item_N
  1525. type_score_dict_ocr['volume_total_score'] = item_total_score
  1526. type_score_dict_ocr['volume_count'] = item_count
  1527. type_score_dict_ocr['volume_score'] = item_score
  1528. break
  1529. elif num_back2== '.' and num_infer3== '.' and num_back3 == '分'and num_back1 == '分' : # 每题*分,共*.*分,共*题/共*分,每题*.*分,共*题
  1530. item_N = -1
  1531. if N_s[0] > N_s[1]:
  1532. item_total_score = N_s[0]
  1533. item_score = float(N_s[1] + '.' + N_s[2])
  1534. item_count = int(item_total_score / item_score)
  1535. else:
  1536. item_total_score = N_s[1]
  1537. item_score = N_s[0]
  1538. item_count = int(item_total_score / item_score)
  1539. type_score_dict_ocr['volume_N'] = item_N
  1540. type_score_dict_ocr['volume_total_score'] = item_total_score
  1541. type_score_dict_ocr['volume_count'] = item_count
  1542. type_score_dict_ocr['volume_score'] = item_score
  1543. break
  1544. elif u == len_keyword_item3-1:
  1545. if num_back2== '.' and num_infer3== '.' and num_back3 == '分'and num_back4 == '分' : # *,共*.*分, 每题*分/每题*.*分,共*分
  1546. item_N = N_s[0]
  1547. if N_s[1] > N_s[3]:
  1548. item_total_score = N_s[1]
  1549. item_score = N_s[3]
  1550. item_count = int(item_total_score / item_score)
  1551. else:
  1552. item_total_score = N_s[3]
  1553. item_score = float(N_s[1] + '.' + N_s[2])
  1554. item_count = int(item_total_score / item_score)
  1555. type_score_dict_ocr['volume_N'] = item_N
  1556. type_score_dict_ocr[ 'item_total_score'] = item_total_score
  1557. type_score_dict_ocr['item_count'] = item_count
  1558. type_score_dict_ocr['item_score'] = item_score
  1559. break
  1560. elif num_back3== '.' and num_infer4== '.' and num_back2 == '分'and num_back4 == '分' : # *,共*分, 每题*.*分/*,每题*分,共*.*分
  1561. item_N = int(N_s[0])
  1562. if N_s[1] > N_s[2]:
  1563. item_total_score = N_s[1]
  1564. item_score = float(N_s[2] + '.' + N_s[3])
  1565. item_count = int(item_total_score / item_score)
  1566. else:
  1567. item_total_score = N_s[2]
  1568. item_score = N_s[1]
  1569. item_count = int(item_total_score / item_score)
  1570. type_score_dict_ocr['volume_N'] = item_N
  1571. type_score_dict_ocr[ 'item_total_score'] = item_total_score
  1572. type_score_dict_ocr['item_count'] = item_count
  1573. type_score_dict_ocr['item_score'] = item_score
  1574. break
  1575. elif num_back2== '.' and num_infer3== '.' and num_back3 == '分'and num_back4 == '分' : # *,共*.*分,每题*分/*,每题*.*分,共*分
  1576. item_N = N_s[0]
  1577. if N_s[1] > N_s[3]:
  1578. item_total_score = N_s[1]
  1579. item_score = N_s[3]
  1580. item_count = int(item_total_score / item_score)
  1581. else:
  1582. item_total_score = N_s[3]
  1583. item_score = float(N_s[1] + '.' + N_s[2])
  1584. item_count = int(item_total_score / item_score)
  1585. type_score_dict_ocr['volume_N'] = item_N
  1586. type_score_dict_ocr['volume_total_score'] = item_total_score
  1587. type_score_dict_ocr['volume_count'] = item_count
  1588. type_score_dict_ocr['volume_score'] = item_score
  1589. break
  1590. elif num_back3== '.' and num_infer4== '.' and num_back4 == '分'and num_back2 == '分' : # *,共*分,每题*.*分/*,每题*分,共*.*分
  1591. item_N = N_s[0]
  1592. if N_s[1] > N_s[2]:
  1593. item_total_score = N_s[1]
  1594. item_score = float(N_s[2] + '.' + N_s[3])
  1595. item_count = int(item_total_score / item_score)
  1596. else:
  1597. item_total_score = N_s[2]
  1598. item_score = N_s[1]
  1599. item_count = int(item_total_score / item_score)
  1600. type_score_dict_ocr['volume_N'] = item_N
  1601. type_score_dict_ocr['volume_total_score'] = item_total_score
  1602. type_score_dict_ocr['volume_count'] = item_count
  1603. type_score_dict_ocr['volume_score'] = item_score
  1604. break
  1605. elif num_back1== '.' and num_infer2== '.' and num_back2 == '分'and num_back3 == '分' : # *,每题*.*分,共*分/*,共*.*分,每题*分
  1606. item_N = N_s[0]
  1607. if N_s[1] > N_s[3]:
  1608. item_total_score = N_s[1]
  1609. item_score = N_s[3]
  1610. item_count = int(item_total_score / item_score)
  1611. else:
  1612. item_total_score = N_s[3]
  1613. item_score = float(N_s[1] + '.' + N_s[2])
  1614. item_count = int(item_total_score / item_score)
  1615. type_score_dict_ocr['volume_N'] = item_N
  1616. type_score_dict_ocr['volume_total_score'] = item_total_score
  1617. type_score_dict_ocr['volume_count'] = item_count
  1618. type_score_dict_ocr['volume_score'] = item_score
  1619. break
  1620. elif num_back2== '.' and num_infer3== '.' and num_back3 == '分'and num_back1 == '分' : # *,每题*分,共*.*分/*,共*分,每题*.*分
  1621. item_N = N_s[0]
  1622. if N_s[1] > N_s[2]:
  1623. item_total_score = N_s[1]
  1624. item_score = float(N_s[2] + '.' + N_s[3])
  1625. item_count = int(item_total_score / item_score)
  1626. else:
  1627. item_total_score = N_s[2]
  1628. item_score = N_s[1]
  1629. item_count = int(item_total_score / item_score)
  1630. type_score_dict_ocr['volume_N'] = item_N
  1631. type_score_dict_ocr['volume_total_score'] = item_total_score
  1632. type_score_dict_ocr['volume_count'] = item_count
  1633. type_score_dict_ocr['volume_score'] = item_score
  1634. break
  1635. break
  1636. break
  1637. elif y == len_keyword_item1 - 1 and num_back4 == '分':
  1638. item_total_score = N_s[3]
  1639. item_N = -1
  1640. item_score = -1
  1641. item_count = -1
  1642. type_score_dict_ocr['volume_N'] = item_N
  1643. type_score_dict_ocr['volume_total_score'] = item_total_score
  1644. type_score_dict_ocr['volume_count'] = item_count
  1645. type_score_dict_ocr['volume_score'] = item_score
  1646. break
  1647. break
  1648. break
  1649. elif x == len_keyword_item1 - 1:
  1650. for y in range(len_keyword_item2):
  1651. if C_s.find(keyword_item2[y]) != -1:
  1652. if len(N_s) == 1:
  1653. num_index1 = s.index(N_s[0])
  1654. num_infer1 = s[num_index1 - len(N_s[0])]
  1655. num_back1 = s[num_index1 + len(N_s[0])]
  1656. if isinstance(N_s[0], str):
  1657. N_s[0] = int(N_s[0])
  1658. if num_back1 == '分': # 每题*分
  1659. item_score = N_s[0]
  1660. type_score_dict_ocr['volume_N'] = -1
  1661. type_score_dict_ocr['volume_total_score'] = -1
  1662. type_score_dict_ocr['volume_count'] = -1
  1663. type_score_dict_ocr['volume_score'] = item_score
  1664. break
  1665. if len(N_s) == 2:
  1666. num_index1 = s.index(N_s[0])
  1667. num_infer1 = s[num_index1 - len(N_s[0])]
  1668. num_back1 = s[num_index1 + len(N_s[0])]
  1669. all_1 = find_repeat(s, N_s[1])
  1670. temp1 = 0
  1671. for ii in range(len(N_s[0])):
  1672. if N_s[0][ii] == N_s[1]:
  1673. temp1 = temp1 + 1
  1674. num_index2 = all_1[temp1]
  1675. num_infer2 = s[num_index2 - len(N_s[1])]
  1676. num_back2 = s[num_index2 + len(N_s[1])]
  1677. if isinstance(N_s[0], str):
  1678. N_s[0] = int(N_s[0])
  1679. if isinstance(N_s[1], str):
  1680. N_s[1] = int(N_s[1])
  1681. for z in range(len(keyword_item3)):
  1682. if C_s.find(keyword_item3[z]) != -1:
  1683. if num_back2 == '分': # 共*题,每题*分
  1684. item_total_score = N_s[0] * N_s[1]
  1685. item_count = N_s[0]
  1686. item_score = N_s[1]
  1687. type_score_dict_ocr['volume_N'] = -1
  1688. type_score_dict_ocr['volume_total_score'] = item_total_score
  1689. type_score_dict_ocr['volume_count'] = item_count
  1690. type_score_dict_ocr['volume_score'] = item_score
  1691. break
  1692. elif num_back1 == '分': # 每题*分,共*题
  1693. item_total_score = int(N_s[0]) * int(N_s[1])
  1694. item_count = int(N_s[1])
  1695. item_score = int(N_s[0])
  1696. type_score_dict_ocr['volume_N'] = -1
  1697. type_score_dict_ocr['volume_total_score'] = item_total_score
  1698. type_score_dict_ocr['volume_count'] = item_count
  1699. type_score_dict_ocr['volume_score'] = item_score
  1700. break
  1701. elif z == len(keyword_item3) - 1:
  1702. if num_back2 == '分' and num_back1 == '.' and num_infer2 == '.': # *.*分
  1703. item_N = -1
  1704. item_score = float(N_s[0]+'.'+N_s[1])
  1705. type_score_dict_ocr['volume_N'] = item_N
  1706. type_score_dict_ocr['volume_total_score'] = -1
  1707. type_score_dict_ocr['volume_count'] = -1
  1708. type_score_dict_ocr['volume_score'] = item_score
  1709. break
  1710. elif num_back2 == '分': # *,*分
  1711. item_N = int(N_s[0])
  1712. item_score = int(N_s[1])
  1713. type_score_dict_ocr['volume_N'] = item_N
  1714. type_score_dict_ocr['volume_total_score'] = -1
  1715. type_score_dict_ocr['volume_count'] = -1
  1716. type_score_dict_ocr['volume_score'] = item_score
  1717. break
  1718. break
  1719. if len(N_s) == 3:
  1720. num_index1 = s.index(N_s[0])
  1721. num_infer1 = s[num_index1 - len(N_s[0])]
  1722. num_back1 = s[num_index1 + len(N_s[0])]
  1723. all_1 = find_repeat(s, N_s[1])
  1724. temp1 = 0
  1725. for ii in range(len(N_s[0])):
  1726. if N_s[0][ii] == N_s[1]:
  1727. temp1 = temp1 + 1
  1728. num_index2 = all_1[temp1]
  1729. num_infer2 = s[num_index2 - len(N_s[1])]
  1730. num_back2 = s[num_index2 + len(N_s[1])]
  1731. all_2 = find_repeat(s, N_s[2])
  1732. temp2 = 0
  1733. for ii in range(len(N_s[0])):
  1734. if N_s[0][ii] == N_s[2]:
  1735. temp2 = temp2 + 1
  1736. for jj in range(len(N_s[1])):
  1737. if N_s[1][jj] == N_s[2]:
  1738. temp2 = temp2 + 1
  1739. num_index3 = all_2[temp2]
  1740. num_infer3 = s[num_index3 - len(N_s[2])]
  1741. num_back3 = s[num_index3 + len(N_s[2])]
  1742. if isinstance(N_s[0], str):
  1743. N_s[0] = int(N_s[0])
  1744. if isinstance(N_s[1], str):
  1745. N_s[1] = int(N_s[1])
  1746. if isinstance(N_s[2], str):
  1747. N_s[2] = int(N_s[2])
  1748. if num_back3 == '分' and (num_back2 == '题' or num_back2 == '小' or num_back2 == '空') and num_back1 != '分': # *,共*题,每题*分
  1749. item_N = int(N_s[0])
  1750. item_total_score = int(N_s[1]) * int(N_s[2])
  1751. item_count = int(N_s[1])
  1752. item_score = int(N_s[2])
  1753. type_score_dict_ocr['volume_N'] = item_N
  1754. type_score_dict_ocr['volume_total_score'] = item_total_score
  1755. type_score_dict_ocr['volume_count'] = item_count
  1756. type_score_dict_ocr['volume_score'] = item_score
  1757. break
  1758. elif num_back2 == '分' and (num_back3 == '题' or num_back3 == '小' or num_back3 == '空') and num_back1 != '分': # *,每题*分,共*题
  1759. item_N = int(N_s[0])
  1760. item_total_score = int(N_s[1]) * int(N_s[2])
  1761. item_count = int(N_s[2])
  1762. item_score = int(N_s[1])
  1763. type_score_dict_ocr['volume_N'] = item_N
  1764. type_score_dict_ocr['volume_total_score'] = item_total_score
  1765. type_score_dict_ocr['volume_count'] = item_count
  1766. type_score_dict_ocr['volume_score'] = item_score
  1767. break
  1768. elif num_infer3 == '.' and num_back3 == '分' and num_back2 == '.': # 共*题,每题*.*分
  1769. item_N = -1
  1770. item_count = int(N_s[0])
  1771. item_score = float(N_s[1]+'.'+N_s[2])
  1772. item_total_score = int(item_count * item_score)
  1773. type_score_dict_ocr['volume_N'] = item_N
  1774. type_score_dict_ocr['volume_total_score'] = item_total_score
  1775. type_score_dict_ocr['volume_count'] = item_count
  1776. type_score_dict_ocr['volume_score'] = item_score
  1777. break
  1778. elif num_infer2 == '.' and num_back2 == '分' and num_back1 == '.' : # 每题*.*分,共*题
  1779. item_N = -1
  1780. item_count = int(N_s[2])
  1781. item_score = float(N_s[0] + '.' + N_s[1])
  1782. item_total_score = int(item_count * item_score)
  1783. type_score_dict_ocr['volume_N'] = item_N
  1784. type_score_dict_ocr['volume_total_score'] = item_total_score
  1785. type_score_dict_ocr['volume_count'] = item_count
  1786. type_score_dict_ocr['volume_score'] = item_score
  1787. break
  1788. elif num_back3 == '分': # * * ,每题*分
  1789. item_N = -1
  1790. item_count = -1
  1791. item_score = -1
  1792. item_total_score = int(N_s[2])
  1793. type_score_dict_ocr['volume_N'] = item_N
  1794. type_score_dict_ocr['volume_total_score'] = item_total_score
  1795. type_score_dict_ocr['volume_count'] = item_count
  1796. type_score_dict_ocr['volume_score'] = item_score
  1797. break
  1798. break
  1799. if len(N_s) == 4:
  1800. num_index1 = s.index(N_s[0])
  1801. num_infer1 = s[num_index1 - len(N_s[0])]
  1802. num_back1 = s[num_index1 + len(N_s[0])]
  1803. all_1 = find_repeat(s, N_s[1])
  1804. temp1 = 0
  1805. for ii in range(len(N_s[0])):
  1806. if N_s[0][ii] == N_s[1]:
  1807. temp1 = temp1 + 1
  1808. num_index2 = all_1[temp1]
  1809. num_infer2 = s[num_index2 - len(N_s[1])]
  1810. num_back2 = s[num_index2 + len(N_s[1])]
  1811. all_2 = find_repeat(s, N_s[2])
  1812. temp2 = 0
  1813. for ii in range(len(N_s[0])):
  1814. if N_s[0][ii] == N_s[2]:
  1815. temp2 = temp2 + 1
  1816. for jj in range(len(N_s[1])):
  1817. if N_s[1][jj] == N_s[2]:
  1818. temp2 = temp2 + 1
  1819. num_index3 = all_2[temp2]
  1820. num_infer3 = s[num_index3 - len(N_s[2])]
  1821. num_back3 = s[num_index3 + len(N_s[2])]
  1822. all_3 = find_repeat(s, N_s[3])
  1823. temp3 = 0
  1824. for ii in range(len(N_s[0])):
  1825. if N_s[0][ii] == N_s[3]:
  1826. temp3 = temp3 + 1
  1827. for jj in range(len(N_s[1])):
  1828. if N_s[1][jj] == N_s[3]:
  1829. temp3 = temp3 + 1
  1830. num_index4 = all_3[temp3]
  1831. num_infer4 = s[num_index4 - len(N_s[3])]
  1832. num_back4 = s[num_index4 + len(N_s[3])]
  1833. if isinstance(N_s[0], str):
  1834. N_s[0] = int(N_s[0])
  1835. if isinstance(N_s[1], str):
  1836. N_s[1] = int(N_s[1])
  1837. if isinstance(N_s[2], str):
  1838. N_s[2] = int(N_s[2])
  1839. if isinstance(N_s[3], str):
  1840. N_s[3] = int(N_s[3])
  1841. if num_back3 == '.' and num_infer4 == '.' and num_back4 == '分' and (num_back2 == '题' or num_back2 == '小' or num_back2 == '空') and num_back1 != '分': # *,共*题,每题*.*分
  1842. item_N = int(N_s[0])
  1843. item_count = int(N_s[1])
  1844. item_score = float(N_s[2] + '.' + N_s[3])
  1845. item_total_score = int(item_count * item_score)
  1846. type_score_dict_ocr['volume_N'] = item_N
  1847. type_score_dict_ocr['volume_total_score'] = item_total_score
  1848. type_score_dict_ocr['volume_count'] = item_count
  1849. type_score_dict_ocr['volume_score'] = item_score
  1850. elif num_back2 == '.' and num_infer3 == '.' and num_back3 == '分' and (num_back4 == '题' or num_back4 == '小' or num_back4 == '空') and num_back1 != '分': # *,每题*.*分,共*题
  1851. item_N = int(N_s[0])
  1852. item_count = int(N_s[3])
  1853. item_score = float(N_s[1] + '.' + N_s[2])
  1854. item_total_score = int(item_count * item_score)
  1855. type_score_dict_ocr['volume_N'] = item_N
  1856. type_score_dict_ocr['volume_total_score'] = item_total_score
  1857. type_score_dict_ocr['volume_count'] = item_count
  1858. type_score_dict_ocr['volume_score'] = item_score
  1859. break
  1860. elif y == len_keyword_item2 - 1:
  1861. if C_s.find(keyword_item4[0]) != -1:
  1862. if len(N_s) == 2: # *,*分
  1863. num_index1 = s.index(N_s[0])
  1864. num_infer1 = s[num_index1 - len(N_s[0])]
  1865. num_back1 = s[num_index1 + len(N_s[0])]
  1866. all_1 = find_repeat(s, N_s[1])
  1867. temp1 = 0
  1868. for ii in range(len(N_s[0])):
  1869. if N_s[0][ii] == N_s[1]:
  1870. temp1 = temp1 + 1
  1871. num_index2 = all_1[temp1]
  1872. num_infer2 = s[num_index2 - len(N_s[1])]
  1873. num_back2 = s[num_index2 + len(N_s[1])]
  1874. if isinstance(N_s[0], str):
  1875. N_s[0] = int(N_s[0])
  1876. if isinstance(N_s[1], str):
  1877. N_s[1] = int(N_s[1])
  1878. if num_back1 == '分':
  1879. item_N = -1
  1880. item_total_score = int(N_s[0])
  1881. type_score_dict_ocr['volume_N'] = item_N
  1882. type_score_dict_ocr['volume_total_score'] = item_total_score
  1883. type_score_dict_ocr['volume_count'] = -1
  1884. type_score_dict_ocr['volume_score'] = -1
  1885. elif num_back2 == '分':
  1886. item_N = int(N_s[0])
  1887. item_total_score = int(N_s[1])
  1888. type_score_dict_ocr['volume_N'] = item_N
  1889. type_score_dict_ocr['volume_total_score'] = item_total_score
  1890. type_score_dict_ocr['volume_count'] = -1
  1891. type_score_dict_ocr['volume_score'] = -1
  1892. break
  1893. elif len(N_s) == 1:
  1894. num_index1 = s.index(N_s[0])
  1895. num_infer1 = s[num_index1 - len(N_s[0])]
  1896. num_back1 = s[num_index1 + len(N_s[0])]
  1897. item_total_score = int(N_s[0])
  1898. type_score_dict_ocr['volume_N'] = -1
  1899. type_score_dict_ocr['volume_total_score'] = item_total_score
  1900. type_score_dict_ocr['volume_count'] = -1
  1901. type_score_dict_ocr['volume_score'] = -1
  1902. # if num_back1 == '分': # *分
  1903. # test_9_23=0
  1904. break
  1905. break
  1906. else:
  1907. type_score_dict_ocr['volume_N'] = -1
  1908. type_score_dict_ocr['volume_total_score'] = -1
  1909. type_score_dict_ocr['volume_count'] = -1
  1910. type_score_dict_ocr['volume_score'] = -1
  1911. if 'volume_N' not in type_score_dict_ocr.keys():
  1912. all_structure = {'volume_structure': -1,
  1913. 'Score_structure': -1}
  1914. break
  1915. else:
  1916. if C_s.find(keyword_type[1]) != -1:
  1917. type_score_dict_ocr['keyword_type'] = keyword_type[1]
  1918. elif C_s.find(keyword_type[0]) != -1:
  1919. type_score_dict_ocr['keyword_type'] = keyword_type[0]
  1920. Score_structure_item = type_score_dict_ocr
  1921. Score_structure.append(Score_structure_item)
  1922. elif C_s.find(keyword_type[xxx]) != -1:
  1923. type_score_dict_ocr['keyword_type'] = keyword_type[xxx]
  1924. elif xxx == len_keyword_type - 1:
  1925. type_score_dict_ocr['keyword_type'] = -2
  1926. type_score_dict_ocr['item_N'] = type_score_dict_ocr.pop(
  1927. 'volume_N')
  1928. type_score_dict_ocr[
  1929. 'item_total_score'] = type_score_dict_ocr.pop(
  1930. 'volume_total_score')
  1931. type_score_dict_ocr['item_count'] = type_score_dict_ocr.pop(
  1932. 'volume_count')
  1933. type_score_dict_ocr['item_score'] = type_score_dict_ocr.pop(
  1934. 'volume_score')
  1935. Score_structure_item = type_score_dict_ocr
  1936. Score_structure.append(Score_structure_item)
  1937. volume_structure_item = type_score_dict_ocr
  1938. volume_structure.append(volume_structure_item)
  1939. if Score_structure == []:
  1940. all_structure = {'volume_structure': volume_structure,
  1941. 'Score_structure': -1}
  1942. elif Score_structure[0]['keyword_type'] != -2:
  1943. all_structure = {'volume_structure': volume_structure,
  1944. 'Score_structure': Score_structure}
  1945. else:
  1946. all_structure = {'volume_structure': -1,
  1947. 'Score_structure': Score_structure}
  1948. break
  1949. elif xxx == len_keyword_type - 1:
  1950. for x in range(len_keyword_item1):
  1951. if C_s.find(keyword_item1[x]) != -1:
  1952. if len(N_s) == 1:
  1953. num_index = s.index(N_s[0])
  1954. num_infer = s[num_index - len(N_s[0])]
  1955. num_back = s[num_index + len(N_s[0])]
  1956. if isinstance(N_s[0], str):
  1957. N_s[0] = int(N_s[0])
  1958. if num_back == '分': # 共*分
  1959. item_total_score = N_s[0]
  1960. type_score_dict_ocr['item_N'] = -1
  1961. type_score_dict_ocr['item_total_score'] = item_total_score
  1962. type_score_dict_ocr['item_count'] = -1
  1963. type_score_dict_ocr['item_score'] = -1
  1964. Score_structure_item = type_score_dict_ocr
  1965. Score_structure.append(Score_structure_item)
  1966. all_structure = {'volume_structure': -1,
  1967. 'Score_structure': Score_structure}
  1968. break
  1969. break
  1970. elif len(N_s) == 2:
  1971. num_index1 = s.index(N_s[0])
  1972. num_infer1 = s[num_index1 - len(N_s[0])]
  1973. num_back1 = s[num_index1 + len(N_s[0])]
  1974. all_1 = find_repeat(s, N_s[1])
  1975. temp1 = 0
  1976. for ii in range(len(N_s[0])):
  1977. if N_s[0][ii] == N_s[1]:
  1978. temp1 = temp1 + 1
  1979. num_index2 = all_1[temp1]
  1980. num_infer2 = s[num_index2 - len(N_s[1])]
  1981. num_back2 = s[num_index2 + len(N_s[1])]
  1982. if isinstance(N_s[0], str):
  1983. N_s[0] = int(N_s[0])
  1984. if isinstance(N_s[1], str):
  1985. N_s[1] = int(N_s[1])
  1986. for y in range(len_keyword_item2):
  1987. if C_s.find(keyword_item2[y]) != -1:
  1988. if num_back1 == '分' and (num_infer2 == '题' or num_infer2 == '空'): # 共*分,每题*分
  1989. item_total_score = int(N_s[0])
  1990. item_count = int(N_s[0]) / int(N_s[1])
  1991. item_score = int(N_s[1])
  1992. type_score_dict_ocr['item_N'] = -1
  1993. type_score_dict_ocr['item_total_score'] = item_total_score
  1994. type_score_dict_ocr['item_count'] = item_count
  1995. type_score_dict_ocr['item_score'] = item_score
  1996. Score_structure_item = type_score_dict_ocr
  1997. Score_structure.append(Score_structure_item)
  1998. all_structure = {'volume_structure': -1,
  1999. 'Score_structure': Score_structure}
  2000. break
  2001. elif (num_infer1 == '题' or num_infer1 == '空') and num_back2 == '分': # 每题*分,共*分
  2002. item_total_score = int(N_s[1])
  2003. item_count = int(N_s[1]) / int(N_s[0])
  2004. item_score = int(N_s[0])
  2005. type_score_dict_ocr['item_N'] = -1
  2006. type_score_dict_ocr['item_total_score'] = item_total_score
  2007. type_score_dict_ocr['item_count'] = item_count
  2008. type_score_dict_ocr['item_score'] = item_score
  2009. Score_structure_item = type_score_dict_ocr
  2010. Score_structure.append(Score_structure_item)
  2011. all_structure = {'volume_structure': -1,
  2012. 'Score_structure': Score_structure}
  2013. break
  2014. break
  2015. elif y == len_keyword_item2 - 1:
  2016. for u in range(len_keyword_item3):
  2017. if C_s.find(keyword_item3[u]) != -1:
  2018. if num_back1 == '分': # 共*分,共*题
  2019. item_total_score = int(N_s[0])
  2020. item_count = int(N_s[1])
  2021. item_score = int(N_s[0]) / int(N_s[1])
  2022. type_score_dict_ocr['item_N'] = -1
  2023. type_score_dict_ocr['item_total_score'] = item_total_score
  2024. type_score_dict_ocr['item_count'] = item_count
  2025. type_score_dict_ocr['item_score'] = item_score
  2026. Score_structure_item = type_score_dict_ocr
  2027. Score_structure.append(Score_structure_item)
  2028. all_structure = {'volume_structure': -1,
  2029. 'Score_structure': Score_structure}
  2030. break
  2031. elif num_back2 == '分': # 共*题,共*分
  2032. item_total_score = int(N_s[1])
  2033. item_count = int(N_s[0])
  2034. item_score = int(N_s[1]) / int(N_s[0])
  2035. type_score_dict_ocr['item_N'] = -1
  2036. type_score_dict_ocr['item_total_score'] = item_total_score
  2037. type_score_dict_ocr['item_count'] = item_count
  2038. type_score_dict_ocr['item_score'] = item_score
  2039. Score_structure_item = type_score_dict_ocr
  2040. Score_structure.append(Score_structure_item)
  2041. all_structure = {'volume_structure': -1,
  2042. 'Score_structure': Score_structure}
  2043. break
  2044. elif u == len_keyword_item3 - 1:
  2045. if num_back2 == '分' and num_infer2 == '.'and num_back1 == '.': # *.*分
  2046. item_N = -1
  2047. item_total_score = int(N_s[0])
  2048. type_score_dict_ocr['item_N'] = item_N
  2049. type_score_dict_ocr['item_total_score'] = item_total_score
  2050. type_score_dict_ocr['item_count'] = -1
  2051. type_score_dict_ocr['item_score'] = -1
  2052. Score_structure_item = type_score_dict_ocr
  2053. Score_structure.append(Score_structure_item)
  2054. all_structure = {'volume_structure': -1,
  2055. 'Score_structure': Score_structure}
  2056. break
  2057. elif num_back2 == '分':
  2058. item_N = int(N_s[0])
  2059. item_total_score = int(N_s[1])
  2060. type_score_dict_ocr['item_N'] = item_N
  2061. type_score_dict_ocr['item_total_score'] = item_total_score
  2062. type_score_dict_ocr['item_count'] = -1
  2063. type_score_dict_ocr['item_score'] = -1
  2064. Score_structure_item = type_score_dict_ocr
  2065. Score_structure.append(Score_structure_item)
  2066. all_structure = {'volume_structure': -1,
  2067. 'Score_structure': Score_structure}
  2068. break
  2069. break
  2070. elif len(N_s) == 3:
  2071. num_index1 = s.index(N_s[0])
  2072. num_infer1 = s[num_index1 - len(N_s[0])]
  2073. num_back1 = s[num_index1 + len(N_s[0])]
  2074. all_1 = find_repeat(s, N_s[1])
  2075. temp1 = 0
  2076. for ii in range(len(N_s[0])):
  2077. if N_s[0][ii] == N_s[1]:
  2078. temp1 = temp1 + 1
  2079. num_index2 = all_1[temp1]
  2080. num_infer2 = s[num_index2 - len(N_s[1])]
  2081. num_back2 = s[num_index2 + len(N_s[1])]
  2082. all_2 = find_repeat(s, N_s[2])
  2083. temp2 = 0
  2084. if len(N_s[0]) == len(N_s[2]):
  2085. if N_s[0] == N_s[2]:
  2086. temp2 = temp2 + 1
  2087. else:
  2088. for ii in range(len(N_s[0])):
  2089. if N_s[0][ii] == N_s[2]:
  2090. temp2 = temp2 + 1
  2091. if len(N_s[1]) == len(N_s[2]):
  2092. if N_s[1] == N_s[2]:
  2093. temp2 = temp2 + 1
  2094. else:
  2095. for jj in range(len(N_s[1])):
  2096. if N_s[1][jj] == N_s[2]:
  2097. temp2 = temp2 + 1
  2098. num_index3 = all_2[temp2]
  2099. num_infer3 = s[num_index3 - len(N_s[2])]
  2100. if num_index3 + len(N_s[2]) < len(s):
  2101. num_back3 = s[num_index3 + len(N_s[2])]
  2102. else:
  2103. num_back3 = []
  2104. if isinstance(N_s[0], str):
  2105. N_s[0] = int(N_s[0])
  2106. if isinstance(N_s[1], str):
  2107. N_s[1] = int(N_s[1])
  2108. if isinstance(N_s[2], str):
  2109. N_s[2] = int(N_s[2])
  2110. for v in range(len_keyword_item2):
  2111. if C_s.find(keyword_item2[v]) != -1:
  2112. for w in range(len_keyword_item3):
  2113. if C_s.find(keyword_item3[w]) != -1:
  2114. if (num_infer1 == '题' or num_infer1 == '空') and num_back1 == '分' and num_back3 == '分': # 每题*分,共*题,共*分
  2115. item_total_score = int(N_s[2])
  2116. item_count = int(N_s[1])
  2117. item_score = int(N_s[0])
  2118. if item_total_score < item_count * item_score:
  2119. item_total_score = item_count * item_score
  2120. type_score_dict_ocr['item_N'] = -1
  2121. type_score_dict_ocr['item_total_score'] = item_total_score
  2122. type_score_dict_ocr['item_count'] = item_count
  2123. type_score_dict_ocr['item_score'] = item_score
  2124. Score_structure_item = type_score_dict_ocr
  2125. Score_structure.append(Score_structure_item)
  2126. all_structure = {'volume_structure': -1,
  2127. 'Score_structure': Score_structure}
  2128. break
  2129. elif (num_infer1 == '题' or num_infer1 == '空') and num_back1 == '分' and num_back2 == '分': # 每题*分,共*分,共*题
  2130. item_total_score = int(N_s[1])
  2131. item_count = int(N_s[2])
  2132. item_score = int(N_s[0])
  2133. if item_total_score < item_count * item_score:
  2134. item_total_score = item_count * item_score
  2135. type_score_dict_ocr['item_N'] = -1
  2136. type_score_dict_ocr['item_total_score'] = item_total_score
  2137. type_score_dict_ocr['item_count'] = item_count
  2138. type_score_dict_ocr['item_score'] = item_score
  2139. Score_structure_item = type_score_dict_ocr
  2140. Score_structure.append(Score_structure_item)
  2141. all_structure = {'volume_structure': -1,
  2142. 'Score_structure': Score_structure}
  2143. break
  2144. elif (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back3 == '分': # 共*题,每题*分,共*分
  2145. item_total_score = int(N_s[2])
  2146. item_count = int(N_s[0])
  2147. item_score = int(N_s[1])
  2148. if item_total_score < item_count * item_score:
  2149. item_total_score = item_count * item_score
  2150. type_score_dict_ocr['item_N'] = -1
  2151. type_score_dict_ocr['item_total_score'] = item_total_score
  2152. type_score_dict_ocr['item_count'] = item_count
  2153. type_score_dict_ocr['item_score'] = item_score
  2154. Score_structure_item = type_score_dict_ocr
  2155. Score_structure.append(Score_structure_item)
  2156. all_structure = {'volume_structure': -1,
  2157. 'Score_structure': Score_structure}
  2158. break
  2159. elif (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back1 == '分': # 共*分,每题*分,共*题
  2160. item_total_score = int(N_s[0])
  2161. item_count = int(N_s[2])
  2162. item_score = int(N_s[1])
  2163. if item_total_score < item_count * item_score:
  2164. item_total_score = item_count * item_score
  2165. type_score_dict_ocr['item_N'] = -1
  2166. type_score_dict_ocr['item_total_score'] = item_total_score
  2167. type_score_dict_ocr['item_count'] = item_count
  2168. type_score_dict_ocr['item_score'] = item_score
  2169. Score_structure_item = type_score_dict_ocr
  2170. Score_structure.append(Score_structure_item)
  2171. all_structure = {'volume_structure': -1,
  2172. 'Score_structure': Score_structure}
  2173. break
  2174. elif (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分' and num_back2 == '分': # 共*题,共*分,每题*分
  2175. item_total_score = int(N_s[1])
  2176. item_count = int(N_s[0])
  2177. item_score = int(N_s[2])
  2178. if item_total_score < item_count * item_score:
  2179. item_total_score = item_count * item_score
  2180. type_score_dict_ocr['item_N'] = -1
  2181. type_score_dict_ocr['item_total_score'] = item_total_score
  2182. type_score_dict_ocr['item_count'] = item_count
  2183. type_score_dict_ocr['item_score'] = item_score
  2184. Score_structure_item = type_score_dict_ocr
  2185. Score_structure.append(Score_structure_item)
  2186. all_structure = {'volume_structure': -1,
  2187. 'Score_structure': Score_structure}
  2188. break
  2189. elif (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分' and num_back1 == '分': # 共*分,共*题, 每题*分
  2190. item_total_score = int(N_s[0])
  2191. item_count = int(N_s[1])
  2192. item_score = int(N_s[2])
  2193. if item_total_score < item_count * item_score:
  2194. item_total_score = item_count * item_score
  2195. type_score_dict_ocr['item_N'] = -1
  2196. type_score_dict_ocr['item_total_score'] = item_total_score
  2197. type_score_dict_ocr['item_count'] = item_count
  2198. type_score_dict_ocr['item_score'] = item_score
  2199. Score_structure_item = type_score_dict_ocr
  2200. Score_structure.append(Score_structure_item)
  2201. all_structure = {'volume_structure': -1,
  2202. 'Score_structure': Score_structure}
  2203. break
  2204. elif w == len_keyword_item3 - 1:
  2205. if num_back2 == '分' and (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分': # *,共*分,每题*分
  2206. item_N = int(N_s[0])
  2207. item_total_score = int(N_s[1])
  2208. item_count = int(N_s[1]) / int(N_s[2])
  2209. item_score = int(N_s[2])
  2210. type_score_dict_ocr['item_N'] = item_N
  2211. type_score_dict_ocr['item_total_score'] = item_total_score
  2212. type_score_dict_ocr['item_count'] = item_count
  2213. type_score_dict_ocr['item_score'] = item_score
  2214. Score_structure_item = type_score_dict_ocr
  2215. Score_structure.append(Score_structure_item)
  2216. all_structure = {'volume_structure': -1,
  2217. 'Score_structure': Score_structure}
  2218. break
  2219. elif num_back3 == '分' and (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分': # *,每题*分,共*分,
  2220. item_N = int(N_s[0])
  2221. item_total_score = int(N_s[2])
  2222. item_count = int(N_s[2]) / int(N_s[1])
  2223. item_score = int(N_s[1])
  2224. type_score_dict_ocr['item_N'] = item_N
  2225. type_score_dict_ocr['item_total_score'] = item_total_score
  2226. type_score_dict_ocr['item_count'] = item_count
  2227. type_score_dict_ocr['item_score'] = item_score
  2228. Score_structure_item = type_score_dict_ocr
  2229. Score_structure.append(Score_structure_item)
  2230. all_structure = {'volume_structure': -1,
  2231. 'Score_structure': Score_structure}
  2232. break
  2233. elif num_back3 == '分' and num_infer2 == '.' and num_back1 == '.' and num_back2 == '分': # 每题*.*分,共*分/共*.*分,每题*分
  2234. item_N = -1
  2235. if int(N_s[0]) > int(N_s[2]):
  2236. item_total_score = int(N_s[0])
  2237. item_score = int(N_s[2])
  2238. item_count = int(item_total_score / item_score)
  2239. else:
  2240. item_total_score = int(N_s[2])
  2241. item_score = float(N_s[0] + '.' + N_s[1])
  2242. item_count = int(item_total_score / item_score)
  2243. type_score_dict_ocr['item_N'] = item_N
  2244. type_score_dict_ocr['item_total_score'] = item_total_score
  2245. type_score_dict_ocr['item_count'] = item_count
  2246. type_score_dict_ocr['item_score'] = item_score
  2247. Score_structure_item = type_score_dict_ocr
  2248. Score_structure.append(Score_structure_item)
  2249. all_structure = {'volume_structure': -1,
  2250. 'Score_structure': Score_structure}
  2251. break
  2252. elif num_back3 == '分' and num_infer3 == '.' and num_back2 == '.' and num_back1 == '分': # 每题*分,共*.*分/共*分,每题*.*分
  2253. item_N = -1
  2254. if int(N_s[0]) > int(N_s[2]):
  2255. item_total_score = int(N_s[0])
  2256. item_score = float(N_s[1] + '.' + N_s[2])
  2257. item_count = int(item_total_score / item_score)
  2258. else:
  2259. item_total_score = int(N_s[1])
  2260. item_score = int(N_s[0])
  2261. item_count = int(item_total_score / item_score)
  2262. type_score_dict_ocr['item_N'] = item_N
  2263. type_score_dict_ocr['item_total_score'] = item_total_score
  2264. type_score_dict_ocr['item_count'] = item_count
  2265. type_score_dict_ocr['item_score'] = item_score
  2266. Score_structure_item = type_score_dict_ocr
  2267. Score_structure.append(Score_structure_item)
  2268. all_structure = {'volume_structure': -1,
  2269. 'Score_structure': Score_structure}
  2270. break
  2271. break
  2272. elif v == len_keyword_item2 - 1:
  2273. for w in range(len_keyword_item3):
  2274. if C_s.find(keyword_item3[w]) != -1:
  2275. if num_back3 == '分' and num_infer3 == '.'and num_back2 == '.': # *小题,共*.*分,
  2276. item_N = -1
  2277. item_total_score = int(N_s[1])
  2278. item_count = int(N_s[0])
  2279. item_score = int(N_s[1]) / int(N_s[0])
  2280. type_score_dict_ocr['item_N'] = item_N
  2281. type_score_dict_ocr['item_total_score'] = item_total_score
  2282. type_score_dict_ocr['item_count'] = item_count
  2283. type_score_dict_ocr['item_score'] = item_score
  2284. Score_structure_item = type_score_dict_ocr
  2285. Score_structure.append(Score_structure_item)
  2286. all_structure = {'volume_structure': -1,
  2287. 'Score_structure': Score_structure}
  2288. break
  2289. elif num_back2 == '分' and num_infer2 == '.'and num_back1 == '.': # 共*.*分,*小题
  2290. item_N = -1
  2291. item_total_score = int(N_s[0])
  2292. item_count = int(N_s[1])
  2293. item_score = int(N_s[0]) / int(N_s[2])
  2294. type_score_dict_ocr['item_N'] = item_N
  2295. type_score_dict_ocr['item_total_score'] = item_total_score
  2296. type_score_dict_ocr['item_count'] = item_count
  2297. type_score_dict_ocr['item_score'] = item_score
  2298. Score_structure_item = type_score_dict_ocr
  2299. Score_structure.append(Score_structure_item)
  2300. all_structure = {'volume_structure': -1,
  2301. 'Score_structure': Score_structure}
  2302. break
  2303. elif num_back2 == '分': # *,*小题,共*分,
  2304. item_N = int(N_s[0])
  2305. item_total_score = int(N_s[1])
  2306. item_count = int(N_s[2])
  2307. item_score = int(N_s[1]) / int(N_s[2])
  2308. type_score_dict_ocr['item_N'] = item_N
  2309. type_score_dict_ocr['item_total_score'] = item_total_score
  2310. type_score_dict_ocr['item_count'] = item_count
  2311. type_score_dict_ocr['item_score'] = item_score
  2312. Score_structure_item = type_score_dict_ocr
  2313. Score_structure.append(Score_structure_item)
  2314. all_structure = {'volume_structure': -1,
  2315. 'Score_structure': Score_structure}
  2316. break
  2317. elif num_back3 == '分': # *,共*分,共*小题
  2318. item_N = int(N_s[0])
  2319. item_total_score = int(N_s[2])
  2320. item_count = int(N_s[1])
  2321. item_score = int(N_s[2]) / int(N_s[1])
  2322. type_score_dict_ocr['item_N'] = item_N
  2323. type_score_dict_ocr['item_total_score'] = item_total_score
  2324. type_score_dict_ocr['item_count'] = item_count
  2325. type_score_dict_ocr['item_score'] = item_score
  2326. Score_structure_item = type_score_dict_ocr
  2327. Score_structure.append(Score_structure_item)
  2328. all_structure = {'volume_structure': -1,
  2329. 'Score_structure': Score_structure}
  2330. break
  2331. elif w == len_keyword_item3 - 1:
  2332. if num_back3 == '分' and num_infer3 == '.'and num_back2 == '.': # *,共*.*分,
  2333. item_N = int(N_s[0])
  2334. item_total_score = int(N_s[1])
  2335. item_count = -1
  2336. item_score = -1
  2337. type_score_dict_ocr['item_N'] = item_N
  2338. type_score_dict_ocr['item_total_score'] = item_total_score
  2339. type_score_dict_ocr['item_count'] = item_count
  2340. type_score_dict_ocr['item_score'] = item_score
  2341. Score_structure_item = type_score_dict_ocr
  2342. Score_structure.append(Score_structure_item)
  2343. all_structure = {'volume_structure': -1,
  2344. 'Score_structure': Score_structure}
  2345. break
  2346. break
  2347. break
  2348. elif len(N_s) == 4:
  2349. num_index1 = s.index(N_s[0])
  2350. num_infer1 = s[num_index1 - len(N_s[0])]
  2351. num_back1 = s[num_index1 + len(N_s[0])]
  2352. all_1 = find_repeat(s, N_s[1])
  2353. temp1 = 0
  2354. for ii in range(len(N_s[0])):
  2355. if N_s[0][ii] == N_s[1]:
  2356. temp1 = temp1 + 1
  2357. num_index2 = all_1[temp1]
  2358. num_infer2 = s[num_index2 - len(N_s[1])]
  2359. num_back2 = s[num_index2 + len(N_s[1])]
  2360. all_2 = find_repeat(s, N_s[2])
  2361. temp2 = 0
  2362. for ii in range(len(N_s[0])):
  2363. if N_s[0][ii] == N_s[2]:
  2364. temp2 = temp2 + 1
  2365. for jj in range(len(N_s[1])):
  2366. if N_s[1][jj] == N_s[2]:
  2367. temp2 = temp2 + 1
  2368. num_index3 = all_2[temp2]
  2369. num_infer3 = s[num_index3 - len(N_s[2])]
  2370. num_back3 = s[num_index3 + len(N_s[2])]
  2371. all_3 = find_repeat(s, N_s[3])
  2372. temp3 = 0
  2373. for ii in range(len(N_s[0])):
  2374. if N_s[0][ii] == N_s[3]:
  2375. temp3 = temp3 + 1
  2376. for jj in range(len(N_s[1])):
  2377. if N_s[1][jj] == N_s[3]:
  2378. temp3 = temp3 + 1
  2379. for kk in range(len(N_s[2])):
  2380. if N_s[2][kk] == N_s[3]:
  2381. temp3 = temp3 + 1
  2382. num_index4 = all_3[temp3]
  2383. num_infer4 = s[num_index4 - len(N_s[3])]
  2384. num_back4 = s[num_index4 + len(N_s[3])]
  2385. if isinstance(N_s[0], str):
  2386. N_s[0] = int(N_s[0])
  2387. if isinstance(N_s[1], str):
  2388. N_s[1] = int(N_s[1])
  2389. if isinstance(N_s[2], str):
  2390. N_s[2] = int(N_s[2])
  2391. if isinstance(N_s[3], str):
  2392. N_s[3] = int(N_s[3])
  2393. for y in range(len_keyword_item1):
  2394. if C_s.find(keyword_item1[y]) != -1:
  2395. for z in range(len_keyword_item2):
  2396. if C_s.find(keyword_item2[z]) != -1:
  2397. for u in range(len_keyword_item3):
  2398. if C_s.find(keyword_item3[u]) != -1:
  2399. if (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back4 == '分': # *,每题*分,共*题,共*分
  2400. item_N = int(N_s[0])
  2401. item_total_score = int(N_s[3])
  2402. item_count = int(N_s[2])
  2403. item_score = int(N_s[1])
  2404. elif (num_infer2 == '题' or num_infer2 == '空') and num_back2 == '分' and num_back3 == '分': # *,每题*分,共*分,共*题
  2405. item_N = int(N_s[0])
  2406. item_total_score = int(N_s[2])
  2407. item_count = int(N_s[3])
  2408. item_score = int(N_s[1])
  2409. elif (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分' and num_back4 == '分': # *,共*题,每题*分,共*分
  2410. item_N = int(N_s[0])
  2411. item_total_score = int(N_s[3])
  2412. item_count = int(N_s[1])
  2413. item_score = int(N_s[2])
  2414. elif (num_infer3 == '题' or num_infer3 == '空') and num_back3 == '分' and num_back2 == '分': # *,共*分,每题*分,共*题
  2415. item_N = int(N_s[0])
  2416. item_total_score = int(N_s[1])
  2417. item_count = int(N_s[3])
  2418. item_score = int(N_s[2])
  2419. elif (num_infer4 == '题' or num_infer4 == '空') and num_back4 == '分' and num_back3 == '分': # *,共*题,共*分,每题*分
  2420. item_N = int(N_s[0])
  2421. item_total_score = int(N_s[2])
  2422. item_count = int(N_s[1])
  2423. item_score = int(N_s[3])
  2424. type_score_dict_ocr['item_N'] = item_N
  2425. elif (num_infer4 == '题' or num_infer4 == '空') and num_back4 == '分' and num_back2 == '分': # *,共*分,共*题, 每题*分
  2426. item_N = int(N_s[0])
  2427. item_total_score = int(N_s[1])
  2428. item_count = int(N_s[2])
  2429. item_score = int(N_s[3])
  2430. elif num_back1== '.' and num_infer2== '.' and num_back2 == '分'and num_back4 == '分' : # 共*.*分,共*题, 每题*分/每题*.*分,共*题,共*分
  2431. item_N = -1
  2432. if int(N_s[0]) > int(N_s[3]):
  2433. item_total_score = int(N_s[0])
  2434. item_score = int(N_s[3])
  2435. item_count = int(item_total_score / item_score)
  2436. else:
  2437. item_total_score = int(N_s[3])
  2438. item_score = float(N_s[0] + '.' + N_s[1])
  2439. item_count = int(item_total_score / item_score)
  2440. elif num_back3== '.' and num_infer4== '.' and num_back1 == '分'and num_back4 == '分' : # 共*分,共*题, 每题*.*分/每题*分,共*题,共*.*分
  2441. item_N = -1
  2442. if int(N_s[0]) > int(N_s[2]):
  2443. item_total_score = int(N_s[0])
  2444. item_score = float(N_s[2] + '.' + N_s[3])
  2445. item_count = int(item_total_score / item_score)
  2446. else:
  2447. item_total_score = int(N_s[2])
  2448. item_score = int(N_s[0])
  2449. item_count = int(item_total_score / item_score)
  2450. elif num_back2== '.' and num_infer3== '.' and num_back3 == '分'and num_back4 == '分' : # 共*题,共*.*分,每题*分/共*题,每题*.*分,共*分
  2451. item_N = -1
  2452. if int(N_s[1]) > int(N_s[3]):
  2453. item_total_score = int(N_s[1])
  2454. item_score = int(N_s[3])
  2455. item_count = int(item_total_score / item_score)
  2456. else:
  2457. item_total_score = int(N_s[3])
  2458. item_score = float(N_s[1] + '.' + N_s[2])
  2459. item_count = int(item_total_score / item_score)
  2460. elif num_back3== '.' and num_infer4== '.' and num_back4 == '分'and num_back2 == '分' : # 共*题,共*分,每题*.*分/共*题,每题*分,共*.*分
  2461. item_N = -1
  2462. if int(N_s[1]) > int(N_s[2]):
  2463. item_total_score = int(N_s[1])
  2464. item_score = float(N_s[2] + '.' + N_s[3])
  2465. item_count = int(item_total_score / item_score)
  2466. else:
  2467. item_total_score = int(N_s[2])
  2468. item_score = int(N_s[1])
  2469. item_count = int(item_total_score / item_score)
  2470. elif num_back1== '.' and num_infer2== '.' and num_back2 == '分'and num_back3 == '分' : # 每题*.*分,共*分,共*题/共*.*分,每题*分,共*题
  2471. item_N = -1
  2472. if int(N_s[0]) > int(N_s[2]):
  2473. item_total_score = int(N_s[0])
  2474. item_score = int(N_s[2])
  2475. item_count = int(item_total_score / item_score)
  2476. else:
  2477. item_total_score = int(N_s[2])
  2478. item_score = float(N_s[0] + '.' + N_s[1])
  2479. item_count = int(item_total_score / item_score)
  2480. elif num_back2== '.' and num_infer3== '.' and num_back3 == '分'and num_back1 == '分' : # 每题*分,共*.*分,共*题/共*分,每题*.*分,共*题
  2481. item_N = -1
  2482. if int(N_s[0]) > int(N_s[1]):
  2483. item_total_score = int(N_s[0])
  2484. item_score = float(N_s[1] + '.' + N_s[2])
  2485. item_count = int(item_total_score / item_score)
  2486. else:
  2487. item_total_score = int(N_s[1])
  2488. item_score = int(N_s[0])
  2489. item_count = int(item_total_score / item_score)
  2490. else:
  2491. break
  2492. if item_total_score < item_count * item_score:
  2493. item_total_score = item_count * item_score
  2494. type_score_dict_ocr['item_N'] = item_N
  2495. type_score_dict_ocr['item_total_score'] = item_total_score
  2496. type_score_dict_ocr['item_count'] = item_count
  2497. type_score_dict_ocr['item_score'] = item_score
  2498. Score_structure_item = type_score_dict_ocr
  2499. Score_structure.append(Score_structure_item)
  2500. all_structure = {'volume_structure': -1,
  2501. 'Score_structure': Score_structure}
  2502. break
  2503. break
  2504. break
  2505. break
  2506. elif x == len_keyword_item1 - 1:
  2507. for y in range(len_keyword_item2):
  2508. if C_s.find(keyword_item2[y]) != -1:
  2509. if len(N_s) == 1:
  2510. num_index1 = s.index(N_s[0])
  2511. num_infer1 = s[num_index1 - len(N_s[0])]
  2512. num_back1 = s[num_index1 + len(N_s[0])]
  2513. if isinstance(N_s[0], str):
  2514. N_s[0] = int(N_s[0])
  2515. if num_back1 == '分': # 每题*分
  2516. item_score = int(N_s[0])
  2517. type_score_dict_ocr['item_N'] = -1
  2518. type_score_dict_ocr['item_total_score'] = -1
  2519. type_score_dict_ocr['item_count'] = -1
  2520. type_score_dict_ocr['item_score'] = item_score
  2521. Score_structure_item = type_score_dict_ocr
  2522. Score_structure.append(Score_structure_item)
  2523. all_structure = {'volume_structure': -1,
  2524. 'Score_structure': Score_structure}
  2525. break
  2526. elif len(N_s) == 2:
  2527. num_index1 = s.index(N_s[0])
  2528. num_infer1 = s[num_index1 - len(N_s[0])]
  2529. num_back1 = s[num_index1 + len(N_s[0])]
  2530. all_1 = find_repeat(s, N_s[1])
  2531. temp1 = 0
  2532. for ii in range(len(N_s[0])):
  2533. if N_s[0][ii] == N_s[1]:
  2534. temp1 = temp1 + 1
  2535. num_index2 = all_1[temp1]
  2536. num_infer2 = s[num_index2 - len(N_s[1])]
  2537. num_back2 = s[num_index2 + len(N_s[1])]
  2538. if isinstance(N_s[0], str):
  2539. N_s[0] = int(N_s[0])
  2540. if isinstance(N_s[1], str):
  2541. N_s[1] = int(N_s[1])
  2542. for z in range(len(keyword_item3)):
  2543. if C_s.find(keyword_item3[z]) != -1:
  2544. if num_back2 == '分': # 共*题,每题*分
  2545. item_total_score = int(N_s[0]) * int(N_s[1])
  2546. item_count = int(N_s[0])
  2547. item_score = int(N_s[1])
  2548. type_score_dict_ocr['item_N'] = -1
  2549. type_score_dict_ocr['item_total_score'] = item_total_score
  2550. type_score_dict_ocr['item_count'] = item_count
  2551. type_score_dict_ocr['item_score'] = item_score
  2552. Score_structure_item = type_score_dict_ocr
  2553. Score_structure.append(Score_structure_item)
  2554. all_structure = {'volume_structure': -1,
  2555. 'Score_structure': Score_structure}
  2556. break
  2557. elif num_back1 == '分': # 每题*分,共*题
  2558. item_total_score = int(N_s[0]) * int(N_s[1])
  2559. item_count = int(N_s[1])
  2560. item_score = int(N_s[0])
  2561. type_score_dict_ocr['item_N'] = -1
  2562. type_score_dict_ocr['item_total_score'] = item_total_score
  2563. type_score_dict_ocr['item_count'] = item_count
  2564. type_score_dict_ocr['item_score'] = item_score
  2565. Score_structure_item = type_score_dict_ocr
  2566. Score_structure.append(Score_structure_item)
  2567. all_structure = {'volume_structure': -1,
  2568. 'Score_structure': Score_structure}
  2569. break
  2570. elif z == len(keyword_item3) - 1:
  2571. if num_back2 == '分' and num_infer2 == '.' and num_back1 == '.': # *.*分
  2572. item_N = -1
  2573. item_score = float(N_s[0] + '.'+N_s[1])
  2574. type_score_dict_ocr['item_N'] = item_N
  2575. type_score_dict_ocr['item_total_score'] = -1
  2576. type_score_dict_ocr['item_count'] = -1
  2577. type_score_dict_ocr['item_score'] = item_score
  2578. Score_structure_item = type_score_dict_ocr
  2579. Score_structure.append(Score_structure_item)
  2580. all_structure = {'volume_structure': -1,
  2581. 'Score_structure': Score_structure}
  2582. break
  2583. elif num_back2 == '分': # *,*分
  2584. item_N = int(N_s[0])
  2585. item_score = int(N_s[1])
  2586. type_score_dict_ocr['item_N'] = item_N
  2587. type_score_dict_ocr['item_total_score'] = -1
  2588. type_score_dict_ocr['item_count'] = -1
  2589. type_score_dict_ocr['item_score'] = item_score
  2590. Score_structure_item = type_score_dict_ocr
  2591. Score_structure.append(Score_structure_item)
  2592. all_structure = {'volume_structure': -1,
  2593. 'Score_structure': Score_structure}
  2594. break
  2595. break
  2596. elif len(N_s) == 3: # 9月16号修改
  2597. num_index1 = s.index(N_s[0])
  2598. num_infer1 = s[num_index1 - len(N_s[0])]
  2599. num_back1 = s[num_index1 + len(N_s[0])]
  2600. all_1 = find_repeat(s, N_s[1])
  2601. temp1 = 0
  2602. for ii in range(len(N_s[0])):
  2603. if N_s[0][ii] == N_s[1]:
  2604. temp1 = temp1 + 1
  2605. num_index2 = all_1[temp1]
  2606. num_infer2 = s[num_index2 - len(N_s[1])]
  2607. num_back2 = s[num_index2 + len(N_s[1])]
  2608. all_2 = find_repeat(s, N_s[2])
  2609. temp2 = 0
  2610. for ii in range(len(N_s[0])):
  2611. if N_s[0][ii] == N_s[2]:
  2612. temp2 = temp2 + 1
  2613. for jj in range(len(N_s[1])):
  2614. if N_s[1][jj] == N_s[2]:
  2615. temp2 = temp2 + 1
  2616. num_index3 = all_2[temp2]
  2617. num_infer3 = s[num_index3 - len(N_s[2])]
  2618. num_back3 = s[num_index3 + len(N_s[2])]
  2619. if isinstance(N_s[0], str):
  2620. N_s[0] = int(N_s[0])
  2621. if isinstance(N_s[1], str):
  2622. N_s[1] = int(N_s[1])
  2623. if isinstance(N_s[2], str):
  2624. N_s[2] = int(N_s[2])
  2625. if num_back3 == '分' and num_back2 != '分' and num_infer3 != '.': # *,共*题,每题*分
  2626. item_N = int(N_s[0])
  2627. item_total_score = int(N_s[1]) * int(N_s[2])
  2628. item_count = int(N_s[1])
  2629. item_score = int(N_s[2])
  2630. elif num_back2 == '分' and num_back3 != '分' and num_infer2 != '.': # *,每题*分,共*题
  2631. item_N = int(N_s[0])
  2632. item_total_score = int(N_s[1]) * int(N_s[2])
  2633. item_count = int(N_s[2])
  2634. item_score = int(N_s[1])
  2635. type_score_dict_ocr['item_N'] = item_N
  2636. type_score_dict_ocr['item_total_score'] = item_total_score
  2637. type_score_dict_ocr['item_count'] = item_count
  2638. type_score_dict_ocr['item_score'] = item_score
  2639. Score_structure_item = type_score_dict_ocr
  2640. Score_structure.append(Score_structure_item)
  2641. all_structure = {'volume_structure': -1,
  2642. 'Score_structure': Score_structure}
  2643. elif num_back2 == '分' and num_back3 == '分'and num_infer3 != '.' and num_infer2 != '.': # *,*分,每题*分
  2644. item_N = int(N_s[0])
  2645. item_total_score = int(N_s[1])
  2646. item_count = int(N_s[1]) / int(N_s[2])
  2647. item_score = int(N_s[2])
  2648. type_score_dict_ocr['item_N'] = item_N
  2649. type_score_dict_ocr['item_total_score'] = item_total_score
  2650. type_score_dict_ocr['item_count'] = item_count
  2651. type_score_dict_ocr['item_score'] = item_score
  2652. Score_structure_item = type_score_dict_ocr
  2653. Score_structure.append(Score_structure_item)
  2654. all_structure = {'volume_structure': -1,
  2655. 'Score_structure': Score_structure}
  2656. elif num_back3 == '分' and num_back2 == '.' and num_infer3 == '.' and (num_back1 =='题' or num_back1 =='小'or num_back1 =='空'): # 共*题,每题*.*分
  2657. item_N = -1
  2658. item_count = int(N_s[0])
  2659. item_score = float(N_s[1]+'.'+N_s[2])
  2660. item_total_score = int(item_score * item_count)
  2661. type_score_dict_ocr['item_N'] = item_N
  2662. type_score_dict_ocr['item_total_score'] = item_total_score
  2663. type_score_dict_ocr['item_count'] = item_count
  2664. type_score_dict_ocr['item_score'] = item_score
  2665. Score_structure_item = type_score_dict_ocr
  2666. Score_structure.append(Score_structure_item)
  2667. all_structure = {'volume_structure': -1,
  2668. 'Score_structure': Score_structure}
  2669. elif num_back2 == '分' and num_back1 == '.' and num_infer2 == '.'and (num_back3 =='题' or num_back3 =='小'or num_back3 =='空'): # 每题*.*分,共*题
  2670. item_N = -1
  2671. item_count = int(N_s[2])
  2672. item_score = float(N_s[0] + '.' + N_s[1])
  2673. item_total_score = int(item_score * item_count)
  2674. type_score_dict_ocr['item_N'] = item_N
  2675. type_score_dict_ocr['item_total_score'] = item_total_score
  2676. type_score_dict_ocr['item_count'] = item_count
  2677. type_score_dict_ocr['item_score'] = item_score
  2678. Score_structure_item = type_score_dict_ocr
  2679. Score_structure.append(Score_structure_item)
  2680. all_structure = {'volume_structure': -1,
  2681. 'Score_structure': Score_structure}
  2682. elif num_back3 == '分' and num_back2 == '.' and num_infer3 == '.': # *,每题*.*分
  2683. item_N = N_s[0]
  2684. item_count = -1
  2685. item_score = float(N_s[1] + '.' + N_s[2])
  2686. item_total_score = -1
  2687. type_score_dict_ocr['item_N'] = item_N
  2688. type_score_dict_ocr['item_total_score'] = item_total_score
  2689. type_score_dict_ocr['item_count'] = item_count
  2690. type_score_dict_ocr['item_score'] = item_score
  2691. Score_structure_item = type_score_dict_ocr
  2692. Score_structure.append(Score_structure_item)
  2693. all_structure = {'volume_structure': -1,
  2694. 'Score_structure': Score_structure}
  2695. elif len(N_s) == 4: # 9月16号修改
  2696. num_index1 = s.index(N_s[0])
  2697. num_infer1 = s[num_index1 - len(N_s[0])]
  2698. num_back1 = s[num_index1 + len(N_s[0])]
  2699. all_1 = find_repeat(s, N_s[1])
  2700. temp1 = 0
  2701. for ii in range(len(N_s[0])):
  2702. if N_s[0][ii] == N_s[1]:
  2703. temp1 = temp1 + 1
  2704. num_index2 = all_1[temp1]
  2705. num_infer2 = s[num_index2 - len(N_s[1])]
  2706. num_back2 = s[num_index2 + len(N_s[1])]
  2707. all_2 = find_repeat(s, N_s[2])
  2708. temp2 = 0
  2709. for ii in range(len(N_s[0])):
  2710. if N_s[0][ii] == N_s[2]:
  2711. temp2 = temp2 + 1
  2712. for jj in range(len(N_s[1])):
  2713. if N_s[1][jj] == N_s[2]:
  2714. temp2 = temp2 + 1
  2715. num_index3 = all_2[temp2]
  2716. num_infer3 = s[num_index3 - len(N_s[2])]
  2717. num_back3 = s[num_index3 + len(N_s[2])]
  2718. all_3 = find_repeat(s, N_s[3])
  2719. temp3 = 0
  2720. for ii in range(len(N_s[0])):
  2721. if N_s[0][ii] == N_s[3]:
  2722. temp3 = temp3 + 1
  2723. for jj in range(len(N_s[1])):
  2724. if N_s[1][jj] == N_s[2]:
  2725. temp3 = temp3 + 1
  2726. num_index4 = all_3[temp3]
  2727. num_infer4 = s[num_index4 - len(N_s[3])]
  2728. num_back4 = s[num_index4 + len(N_s[3])]
  2729. if isinstance(N_s[0], str):
  2730. N_s[0] = int(N_s[0])
  2731. if isinstance(N_s[1], str):
  2732. N_s[1] = int(N_s[1])
  2733. if isinstance(N_s[2], str):
  2734. N_s[2] = int(N_s[2])
  2735. if isinstance(N_s[3], str):
  2736. N_s[3] = int(N_s[3])
  2737. if num_back4 == '分' and num_back2 != '分' and num_infer4 == '.'and num_back3 == '.': # *,共*题,每题*.*分
  2738. item_N = int(N_s[0])
  2739. item_count = int(N_s[1])
  2740. item_score = float(N_s[2]+'.'+N_s[3])
  2741. item_total_score = int(item_score * item_count)
  2742. type_score_dict_ocr['item_N'] = item_N
  2743. type_score_dict_ocr['item_total_score'] = item_total_score
  2744. type_score_dict_ocr['item_count'] = item_count
  2745. type_score_dict_ocr['item_score'] = item_score
  2746. Score_structure_item = type_score_dict_ocr
  2747. Score_structure.append(Score_structure_item)
  2748. all_structure = {'volume_structure': -1,
  2749. 'Score_structure': Score_structure}
  2750. elif num_back3 == '分' and num_back4 != '分' and num_infer3 == '.'and num_back2 == '.': # *,每题*.*分,共*题
  2751. item_N = int(N_s[0])
  2752. item_count = int(N_s[3])
  2753. item_score = float(N_s[1] + '.' + N_s[2])
  2754. item_total_score = int(item_score * item_count)
  2755. type_score_dict_ocr['item_N'] = item_N
  2756. type_score_dict_ocr['item_total_score'] = item_total_score
  2757. type_score_dict_ocr['item_count'] = item_count
  2758. type_score_dict_ocr['item_score'] = item_score
  2759. Score_structure_item = type_score_dict_ocr
  2760. Score_structure.append(Score_structure_item)
  2761. all_structure = {'volume_structure': -1,
  2762. 'Score_structure': Score_structure}
  2763. break
  2764. elif y == len_keyword_item2 - 1:
  2765. if C_s.find(keyword_item4[0]) != -1:
  2766. if len(N_s) == 2: # *,*分
  2767. num_index1 = s.index(N_s[0])
  2768. num_infer1 = s[num_index1 - len(N_s[0])]
  2769. num_back1 = s[num_index1 + len(N_s[0])]
  2770. if num_infer1 == '( ' or num_back1 == ')' or num_infer1 == '( ' or num_back1 == ')':
  2771. break
  2772. else:
  2773. all_1 = find_repeat(s, N_s[1])
  2774. temp1 = 0
  2775. for ii in range(len(N_s[0])):
  2776. if N_s[0][ii] == N_s[1]:
  2777. temp1 = temp1 + 1
  2778. num_index2 = all_1[temp1]
  2779. num_infer2 = s[num_index2 - len(N_s[1])]
  2780. num_back2 = s[num_index2 + len(N_s[1])]
  2781. if isinstance(N_s[0], str):
  2782. N_s[0] = int(N_s[0])
  2783. if isinstance(N_s[1], str):
  2784. N_s[1] = int(N_s[1])
  2785. if int(N_s[0]) > 1000:
  2786. item_N =0
  2787. item_N1 = int(N_s[0][-4] + N_s[0][-3])
  2788. item_N2 = int(N_s[0][-2] + N_s[0][-1])
  2789. if item_N2 - item_N1 == 1:
  2790. item_N = [0, 0]
  2791. item_N = [item_N1, item_N2]
  2792. elif item_N2 - item_N1 == 2:
  2793. item_N = [0, 0, 0]
  2794. item_N = [item_N1, item_N1 + 1, item_N2]
  2795. elif item_N2 - item_N1 == 3:
  2796. item_N = [0, 0, 0, 0]
  2797. item_N = [item_N1, item_N1 + 1, item_N1 + 2, item_N2]
  2798. type_score_dict_ocr['item_N'] = item_N
  2799. else:
  2800. item_N = int(N_s[0])
  2801. item_total_score = int(N_s[1])
  2802. type_score_dict_ocr['item_N'] = item_N
  2803. type_score_dict_ocr['item_total_score'] = item_total_score
  2804. type_score_dict_ocr['item_count'] = -1
  2805. type_score_dict_ocr['item_score'] = -1
  2806. Score_structure_item = type_score_dict_ocr
  2807. Score_structure.append(Score_structure_item)
  2808. all_structure = {'volume_structure': -1,
  2809. 'Score_structure': Score_structure}
  2810. break
  2811. elif len(N_s) == 3: # *,*分
  2812. num_index1 = s.index(N_s[0])
  2813. num_infer1 = s[num_index1 - len(N_s[0])]
  2814. num_back1 = s[num_index1 + len(N_s[0])]
  2815. all_1 = find_repeat(s, N_s[1])
  2816. temp1 = 0
  2817. for ii in range(len(N_s[0])):
  2818. if N_s[0][ii] == N_s[1]:
  2819. temp1 = temp1 + 1
  2820. num_index2 = all_1[temp1]
  2821. num_infer2 = s[num_index2 - len(N_s[1])]
  2822. num_back2 = s[num_index2 + len(N_s[1])]
  2823. all_2 = find_repeat(s, N_s[2])
  2824. temp2 = 0
  2825. for ii in range(len(N_s[0])):
  2826. if N_s[0][ii] == N_s[2]:
  2827. temp2 = temp2 + 1
  2828. for jj in range(len(N_s[1])):
  2829. if N_s[1][jj] == N_s[2]:
  2830. temp2 = temp2 + 1
  2831. num_index3 = all_2[temp2]
  2832. num_infer3 = s[num_index3 - len(N_s[2])]
  2833. if num_index3 + len(N_s[2]) < len(s):
  2834. num_back3 = s[num_index3 + len(N_s[2])]
  2835. else:
  2836. num_back3 = []
  2837. if isinstance(N_s[0], str):
  2838. N_s[0] = int(N_s[0])
  2839. if isinstance(N_s[1], str):
  2840. N_s[1] = int(N_s[1])
  2841. if isinstance(N_s[2], str):
  2842. N_s[2] = int(N_s[2])
  2843. if num_back2 == '分':
  2844. item_N = N_s[0]
  2845. item_total_score = int(N_s[1])
  2846. type_score_dict_ocr['item_total_score'] = item_total_score
  2847. item_total_score = int(N_s[2])
  2848. type_score_dict_ocr['item_total_score'] = item_total_score
  2849. type_score_dict_ocr['item_N'] = item_N
  2850. type_score_dict_ocr['item_count'] = -1
  2851. type_score_dict_ocr['item_score'] = -1
  2852. Score_structure_item = type_score_dict_ocr
  2853. Score_structure.append(Score_structure_item)
  2854. all_structure = {'volume_structure': -1,
  2855. 'Score_structure': Score_structure}
  2856. break
  2857. elif num_back3 == '分':
  2858. if int(N_s[1]) - int(N_s[0]) == 1:
  2859. item_N = [0, 0]
  2860. item_N = [int(N_s[0]), int(N_s[1])]
  2861. elif int(N_s[1]) - int(N_s[0]) == 2:
  2862. item_N = [0, 0, 0]
  2863. item_N = [int(N_s[0]), int(N_s[0]) + 1, int(N_s[1])]
  2864. elif int(N_s[1]) - int(N_s[0]) == 3:
  2865. item_N = [0, 0, 0, 0]
  2866. item_N = [int(N_s[0]), int(N_s[0]) + 1, int(N_s[0]) + 2,
  2867. int(N_s[1])]
  2868. else:
  2869. break
  2870. item_total_score = int(N_s[2])
  2871. type_score_dict_ocr['item_total_score'] = item_total_score
  2872. type_score_dict_ocr['item_N'] = item_N
  2873. type_score_dict_ocr['item_count'] = -1
  2874. type_score_dict_ocr['item_score'] = -1
  2875. Score_structure_item = type_score_dict_ocr
  2876. Score_structure.append(Score_structure_item)
  2877. all_structure = {'volume_structure': -1,
  2878. 'Score_structure': Score_structure}
  2879. break
  2880. elif len(N_s) == 1:
  2881. num_index1 = s.index(N_s[0])
  2882. num_infer1 = s[num_index1 - len(N_s[0])]
  2883. if num_index1 + len(N_s[0]) < len(s):
  2884. num_back1 = s[num_index1 + len(N_s[0])]
  2885. item_total_score = int(N_s[0])
  2886. type_score_dict_ocr['item_N'] = -1
  2887. type_score_dict_ocr['item_total_score'] = item_total_score
  2888. type_score_dict_ocr['item_count'] = -1
  2889. type_score_dict_ocr['item_score'] = -1
  2890. if num_back1 == '分': # *分
  2891. Score_structure_item = type_score_dict_ocr
  2892. Score_structure.append(Score_structure_item)
  2893. all_structure = {'volume_structure': -1,
  2894. 'Score_structure': Score_structure}
  2895. break
  2896. break
  2897. return all_structure