|
@@ -81,6 +81,97 @@ def change_box(cloze_s_res, cloze_s_region):
|
|
return words_result
|
|
return words_result
|
|
|
|
|
|
|
|
|
|
|
|
+def get_cloze_number_and_value(cloze_s_box_with_content):
|
|
|
|
+ print(cloze_s_box_with_content)
|
|
|
|
+ list_of_cloze_s = []
|
|
|
|
+ number_value = []
|
|
|
|
+ for words_index, words_str in enumerate(cloze_s_box_with_content):
|
|
|
|
+ above_content = words_str['above_content']
|
|
|
|
+ above_content = sorted(above_content, key=lambda k: k['location']['left'])
|
|
|
|
+ words_list = [chars['words'] for chars in above_content]
|
|
|
|
+ words = ','.join(words_list)
|
|
|
|
+ pattern1 = re.compile(
|
|
|
|
+ '^\d+[,、.]?[\u4e00-\u9fa5]?[((]?\d+分+[))]?[((]?\d+[))]?|^\d+[,、.]?[\u4e00-\u9fa5]?[((]?\d+分+[))]?')
|
|
|
|
+ result1 = re.findall(pattern1, words)
|
|
|
|
+
|
|
|
|
+ pattern11 = re.compile('^\d+[,、.]?[\u4e00-\u9fa5]?[((]?\d+[))]?')
|
|
|
|
+ result11 = re.findall(pattern11, words)
|
|
|
|
+
|
|
|
|
+ pattern2 = re.compile('[((]?\d+[))]?')
|
|
|
|
+ result2 = re.findall(pattern2, words)
|
|
|
|
+
|
|
|
|
+ pattern3 = re.compile('[((]?\d?分+[))]?')
|
|
|
|
+ result3 = re.findall(pattern3, words)
|
|
|
|
+
|
|
|
|
+ pattern5 = re.compile('[\u4e00-\u9fa5]')
|
|
|
|
+ result5 = re.findall(pattern5, words)
|
|
|
|
+ # if result1:
|
|
|
|
+ # print('ok')
|
|
|
|
+ if result11 and result2 and not result3 and not result5:
|
|
|
|
+ title_number = int(result2[0])
|
|
|
|
+ total_score = -1
|
|
|
|
+ words_str.update({'title_number': title_number, 'total_score': int(total_score)})
|
|
|
|
+ list_of_cloze_s.append(words_str)
|
|
|
|
+ number_value.append(title_number)
|
|
|
|
+ number_value.append(total_score)
|
|
|
|
+ if result11 and result3 and result5:
|
|
|
|
+ title_number1 = re.search('\d+', result11[0])
|
|
|
|
+ title_number = title_number1.group()
|
|
|
|
+ total_score_str = result3[0]
|
|
|
|
+ digital_total_score = re.search('\d+', total_score_str)
|
|
|
|
+ total_score = digital_total_score.group()
|
|
|
|
+ words_str.update({'title_number': int(title_number), 'total_score': int(total_score)})
|
|
|
|
+ list_of_cloze_s.append(words_str)
|
|
|
|
+ number_value.append(int(title_number))
|
|
|
|
+ number_value.append(total_score)
|
|
|
|
+ if not result11 and not result1 and result3 and result5:
|
|
|
|
+ title_number = -1
|
|
|
|
+ total_score_str = result3[0]
|
|
|
|
+ digital_total_score = re.search('\d+', total_score_str)
|
|
|
|
+ if digital_total_score == None:
|
|
|
|
+ total_score = -1
|
|
|
|
+ else:
|
|
|
|
+ total_score = digital_total_score.group()
|
|
|
|
+ words_str.update({'title_number': title_number, 'total_score': int(total_score)})
|
|
|
|
+ list_of_cloze_s.append(words_str)
|
|
|
|
+ number_value.append(title_number)
|
|
|
|
+ number_value.append(total_score)
|
|
|
|
+ if result11 and not result3 and not result5:
|
|
|
|
+ title_number1 = re.search('\d+', result11[0])
|
|
|
|
+ title_number = title_number1.group()
|
|
|
|
+ total_score = -1
|
|
|
|
+ words_str.update({'title_number': int(title_number), 'total_score': total_score})
|
|
|
|
+ list_of_cloze_s.append(words_str)
|
|
|
|
+ number_value.append(int(title_number))
|
|
|
|
+ number_value.append(total_score)
|
|
|
|
+ if not result11 and result2 and not result3 and not result5:
|
|
|
|
+ if len(result2) == 1:
|
|
|
|
+ title_number1 = re.search('\d+', result2[0])
|
|
|
|
+ title_number = title_number1.group()
|
|
|
|
+ elif len(result2) == 2:
|
|
|
|
+ title_number_str = re.search('\d+', result2[0])
|
|
|
|
+ title_number = int(title_number_str.group())
|
|
|
|
+ else:
|
|
|
|
+ title_number = -1
|
|
|
|
+ total_score = -1
|
|
|
|
+ words_str.update({'title_number': title_number, 'total_score': int(total_score)})
|
|
|
|
+ list_of_cloze_s.append(words_str)
|
|
|
|
+ number_value.append(title_number)
|
|
|
|
+ number_value.append(total_score)
|
|
|
|
+ elif len(number_value) == 0:
|
|
|
|
+ title_number = -1
|
|
|
|
+ total_score = -1
|
|
|
|
+ words_str.update({'title_number': title_number, 'total_score': int(total_score)})
|
|
|
|
+ list_of_cloze_s.append(words_str)
|
|
|
|
+ list_of_cloze_s_tmp = list_of_cloze_s.copy()
|
|
|
|
+ cloze_s_list = []
|
|
|
|
+ for cloze_s_s in list_of_cloze_s_tmp:
|
|
|
|
+ cloze_s_s_tmp = cloze_s_s.copy()
|
|
|
|
+ cloze_s_s_tmp.pop('above_content')
|
|
|
|
+ cloze_s_list.append(cloze_s_s)
|
|
|
|
+ return cloze_s_list
|
|
|
|
+
|
|
|
|
+
|
|
def get_total_title_quantity_and_value(box_with_content):
|
|
def get_total_title_quantity_and_value(box_with_content):
|
|
list_of_all = []
|
|
list_of_all = []
|
|
|
|
|
|
@@ -376,28 +467,33 @@ def get_sheet_points(sheet_dict_list):
|
|
for one_col_box in cloze_or_solve0_box_list_front:
|
|
for one_col_box in cloze_or_solve0_box_list_front:
|
|
|
|
|
|
for ele_box in one_col_box:
|
|
for ele_box in one_col_box:
|
|
- big_box = {}
|
|
|
|
- words_list = []
|
|
|
|
- for words_res in words_result_front:
|
|
|
|
- xmin = words_res['location']['left']
|
|
|
|
- ymin = words_res['location']['top']
|
|
|
|
- xmax = words_res['location']['left'] + words_res['location']['width']
|
|
|
|
- ymax = words_res['location']['top'] + words_res['location']['height']
|
|
|
|
- words_bbox = [xmin, ymin, xmax, ymax]
|
|
|
|
- if utils.decide_coordinate_contains1(words_bbox,
|
|
|
|
- [ele_box['bounding_box']['xmin'],
|
|
|
|
- ele_box['bounding_box']['ymin'],
|
|
|
|
- ele_box['bounding_box']['xmax'],
|
|
|
|
- ele_box['bounding_box']['ymax']]):
|
|
|
|
- words_list.append(words_res)
|
|
|
|
- big_box['class_name'] = ele_box['class_name']
|
|
|
|
- big_box['bounding_box'] = ele_box['bounding_box']
|
|
|
|
- big_box['above_content'] = words_list
|
|
|
|
- box_with_content_front.append(big_box)
|
|
|
|
- box_with_content_front1 = box_with_content_front + cloze_s_box_with_content
|
|
|
|
- list_of_front = get_total_title_quantity_and_value(box_with_content_front1)
|
|
|
|
|
|
+ if ele_box['class_name'] == 'cloze_s':
|
|
|
|
+ continue
|
|
|
|
+ else:
|
|
|
|
+ big_box = {}
|
|
|
|
+ words_list = []
|
|
|
|
+ for words_res in words_result_front:
|
|
|
|
+ xmin = words_res['location']['left']
|
|
|
|
+ ymin = words_res['location']['top']
|
|
|
|
+ xmax = words_res['location']['left'] + words_res['location']['width']
|
|
|
|
+ ymax = words_res['location']['top'] + words_res['location']['height']
|
|
|
|
+ words_bbox = [xmin, ymin, xmax, ymax]
|
|
|
|
+ if utils.decide_coordinate_contains1(words_bbox,
|
|
|
|
+ [ele_box['bounding_box']['xmin'],
|
|
|
|
+ ele_box['bounding_box']['ymin'],
|
|
|
|
+ ele_box['bounding_box']['xmax'],
|
|
|
|
+ ele_box['bounding_box']['ymax']]):
|
|
|
|
+ words_list.append(words_res)
|
|
|
|
+ big_box['class_name'] = ele_box['class_name']
|
|
|
|
+ big_box['bounding_box'] = ele_box['bounding_box']
|
|
|
|
+ big_box['above_content'] = words_list
|
|
|
|
+ box_with_content_front.append(big_box)
|
|
|
|
+ # box_with_content_front1 = cloze_s_box_with_content + box_with_content_front
|
|
|
|
+ list_of_front1 = get_total_title_quantity_and_value(box_with_content_front)
|
|
|
|
+ list_of_cloze_s = get_cloze_number_and_value(cloze_s_box_with_content)
|
|
|
|
+ list_of_front = list_of_front1 + list_of_cloze_s
|
|
sheet_dict_of_front.append(list_of_front)
|
|
sheet_dict_of_front.append(list_of_front)
|
|
-
|
|
|
|
|
|
+ # print(sheet_dict_of_front)
|
|
sheet_dict_of_back = []
|
|
sheet_dict_of_back = []
|
|
sheet_dict_of_back_without_solve_cloze = []
|
|
sheet_dict_of_back_without_solve_cloze = []
|
|
for single_sheet_dict in region_dict_back:
|
|
for single_sheet_dict in region_dict_back:
|
|
@@ -434,33 +530,40 @@ def get_sheet_points(sheet_dict_list):
|
|
box_with_content_back = []
|
|
box_with_content_back = []
|
|
for one_col_box in cloze_or_solve0_box_list_back:
|
|
for one_col_box in cloze_or_solve0_box_list_back:
|
|
for ele_box in one_col_box:
|
|
for ele_box in one_col_box:
|
|
- words_list = []
|
|
|
|
- big_box = {}
|
|
|
|
- for words_res in words_result_back:
|
|
|
|
- xmin = words_res['location']['left']
|
|
|
|
- ymin = words_res['location']['top']
|
|
|
|
- xmax = words_res['location']['left'] + words_res['location']['width']
|
|
|
|
- ymax = words_res['location']['top'] + words_res['location']['height']
|
|
|
|
- words_bbox = [xmin, ymin, xmax, ymax]
|
|
|
|
- if utils.decide_coordinate_contains1(words_bbox,
|
|
|
|
- [ele_box['bounding_box']['xmin'],
|
|
|
|
- ele_box['bounding_box']['ymin'],
|
|
|
|
- ele_box['bounding_box']['xmax'],
|
|
|
|
- ele_box['bounding_box']['ymax']]):
|
|
|
|
- words_list.append(words_res)
|
|
|
|
- big_box['class_name'] = ele_box['class_name']
|
|
|
|
- big_box['bounding_box'] = ele_box['bounding_box']
|
|
|
|
- big_box['above_content'] = words_list
|
|
|
|
- box_with_content_back.append(big_box)
|
|
|
|
|
|
+ if ele_box['class_name'] == 'cloze_s':
|
|
|
|
+ continue
|
|
|
|
+ else:
|
|
|
|
+ words_list = []
|
|
|
|
+ big_box = {}
|
|
|
|
+ for words_res in words_result_back:
|
|
|
|
+ xmin = words_res['location']['left']
|
|
|
|
+ ymin = words_res['location']['top']
|
|
|
|
+ xmax = words_res['location']['left'] + words_res['location']['width']
|
|
|
|
+ ymax = words_res['location']['top'] + words_res['location']['height']
|
|
|
|
+ words_bbox = [xmin, ymin, xmax, ymax]
|
|
|
|
+ if utils.decide_coordinate_contains1(words_bbox,
|
|
|
|
+ [ele_box['bounding_box']['xmin'],
|
|
|
|
+ ele_box['bounding_box']['ymin'],
|
|
|
|
+ ele_box['bounding_box']['xmax'],
|
|
|
|
+ ele_box['bounding_box']['ymax']]):
|
|
|
|
+ words_list.append(words_res)
|
|
|
|
+ big_box['class_name'] = ele_box['class_name']
|
|
|
|
+ big_box['bounding_box'] = ele_box['bounding_box']
|
|
|
|
+ big_box['above_content'] = words_list
|
|
|
|
+ box_with_content_back.append(big_box)
|
|
# print(box_with_content_back)
|
|
# print(box_with_content_back)
|
|
|
|
|
|
- box_with_content_back1 = box_with_content_back + cloze_s_box_with_content
|
|
|
|
|
|
+ # box_with_content_back1 = box_with_content_back + cloze_s_box_with_content
|
|
# box_with_content_back1 = sorted(box_with_content_back1, key=lambda k: k.get('above_content'))
|
|
# box_with_content_back1 = sorted(box_with_content_back1, key=lambda k: k.get('above_content'))
|
|
- list_of_back = get_total_title_quantity_and_value(box_with_content_back1)
|
|
|
|
|
|
+ list_of_back1 = get_total_title_quantity_and_value(box_with_content_back)
|
|
|
|
+ list_of_cloze_s = get_cloze_number_and_value(cloze_s_box_with_content)
|
|
|
|
+ list_of_back = list_of_back1 + list_of_cloze_s
|
|
|
|
+
|
|
sheet_dict_of_back.append(list_of_back)
|
|
sheet_dict_of_back.append(list_of_back)
|
|
|
|
|
|
if sheet_dict_of_front != [] and sheet_dict_of_front_without_solve_cloze == []:
|
|
if sheet_dict_of_front != [] and sheet_dict_of_front_without_solve_cloze == []:
|
|
- sheet_dict_of_front = check_classes(sheet_dict_of_front)
|
|
|
|
|
|
+ # sheet_dict_of_front = check_classes(sheet_dict_of_front) raw
|
|
|
|
+ sheet_dict_of_front = sheet_dict_of_front
|
|
else:
|
|
else:
|
|
sheet_dict_of_front = []
|
|
sheet_dict_of_front = []
|
|
if sheet_dict_of_back != [] and sheet_dict_of_back_without_solve_cloze == []:
|
|
if sheet_dict_of_back != [] and sheet_dict_of_back_without_solve_cloze == []:
|
|
@@ -492,11 +595,9 @@ def get_sheet_points(sheet_dict_list):
|
|
ele13['bounding_box']:
|
|
ele13['bounding_box']:
|
|
title_number = ele13['title_number']
|
|
title_number = ele13['title_number']
|
|
total_score = ele13['total_score']
|
|
total_score = ele13['total_score']
|
|
- total_title_quantity = ele13['total_title_quantity']
|
|
|
|
- title_with_value = ele13['title_with_value']
|
|
|
|
- single_classes.update({'number': title_number, 'default_points': total_score,
|
|
|
|
- 'total_title_quantity': total_title_quantity,
|
|
|
|
- 'title_with_value': title_with_value})
|
|
|
|
|
|
+ # total_title_quantity = ele13['total_title_quantity']
|
|
|
|
+ # title_with_value = ele13['title_with_value']
|
|
|
|
+ single_classes.update({'number': title_number, 'default_points': total_score})
|
|
else:
|
|
else:
|
|
continue
|
|
continue
|
|
else:
|
|
else:
|
|
@@ -512,12 +613,10 @@ def get_sheet_points(sheet_dict_list):
|
|
single_class_back['bounding_box'] == regions_all['bounding_box']:
|
|
single_class_back['bounding_box'] == regions_all['bounding_box']:
|
|
title_number0 = regions_all['title_number']
|
|
title_number0 = regions_all['title_number']
|
|
total_score0 = regions_all['total_score']
|
|
total_score0 = regions_all['total_score']
|
|
- total_title_quantity0 = regions_all['total_title_quantity']
|
|
|
|
- title_with_value0 = regions_all['title_with_value']
|
|
|
|
|
|
+ # total_title_quantity0 = regions_all['total_title_quantity']
|
|
|
|
+ # title_with_value0 = regions_all['title_with_value']
|
|
single_class_back.update({'number': title_number0,
|
|
single_class_back.update({'number': title_number0,
|
|
- 'default_points': total_score0,
|
|
|
|
- 'total_title_quantity': total_title_quantity0,
|
|
|
|
- 'title_with_value': title_with_value0})
|
|
|
|
|
|
+ 'default_points': total_score0})
|
|
else:
|
|
else:
|
|
continue
|
|
continue
|
|
else:
|
|
else:
|