fix bug
Showing
4 changed files
with
80 additions
and
66 deletions
| ... | @@ -1044,36 +1044,36 @@ COMPARE_FIELDS = (IC_OCR_FIELD, RP_OCR_FIELD, BL_OCR_FIELD, EEP_OCR_FIELD, DL_OC | ... | @@ -1044,36 +1044,36 @@ COMPARE_FIELDS = (IC_OCR_FIELD, RP_OCR_FIELD, BL_OCR_FIELD, EEP_OCR_FIELD, DL_OC |
| 1044 | 1044 | ||
| 1045 | # 身份证 | 1045 | # 身份证 |
| 1046 | ITPRC = [ | 1046 | ITPRC = [ |
| 1047 | ('customerChineseName', '姓名', 'name_compare', {}), | 1047 | ('customerChineseName', '姓名', 'name_compare', {}, 'customerChineseNameResult'), |
| 1048 | ('idNum', '公民身份号码', 'common_compare', {}), | 1048 | ('idNum', '公民身份号码', 'common_compare', {}, 'idNumResult'), |
| 1049 | # 20200410-20250410 OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0 | 1049 | # 20200410-20250410 OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0 |
| 1050 | ('idExpiryDate', '有效期限', 'date_compare', {'long': True, 'ocr_split': True, 'input_replace': ''}), | 1050 | ('idExpiryDate', '有效期限', 'date_compare', {'long': True, 'ocr_split': True, 'input_replace': ''}, 'idExpiryDateResult'), |
| 1051 | ('dateOfBirth', '出生年月', 'date_compare', {'input_replace': ''}), # 20231023 | 1051 | ('dateOfBirth', '出生年月', 'date_compare', {'input_replace': ''}, 'dateOfBirthResult'), # 20231023 |
| 1052 | ] | 1052 | ] |
| 1053 | 1053 | ||
| 1054 | # 护照 | 1054 | # 护照 |
| 1055 | ITPSP = [ | 1055 | ITPSP = [ |
| 1056 | ('customerChineseName', '英文姓名', 'name_compare', {'is_passport': True}), | 1056 | ('customerChineseName', '英文姓名', 'name_compare', {'is_passport': True}, 'customerChineseNameResult'), |
| 1057 | ('idNum', '护照号码', 'common_compare', {}), | 1057 | ('idNum', '护照号码', 'common_compare', {}, 'idNumResult'), |
| 1058 | ('idExpiryDate', '有效期至', 'date_compare', {'input_replace': ''}), # 20250410 | 1058 | ('idExpiryDate', '有效期至', 'date_compare', {'input_replace': ''}, 'idExpiryDateResult'), # 20250410 |
| 1059 | ('dateOfBirth', '出生日期', 'date_compare', {'input_replace': ''}), # 20250410 | 1059 | ('dateOfBirth', '出生日期', 'date_compare', {'input_replace': ''}, 'dateOfBirthResult'), # 20250410 |
| 1060 | ] | 1060 | ] |
| 1061 | 1061 | ||
| 1062 | # 港澳台通行证 | 1062 | # 港澳台通行证 |
| 1063 | ITHKM_ITTID = [ | 1063 | ITHKM_ITTID = [ |
| 1064 | ('customerChineseName', '中文名', 'common_compare', {}), | 1064 | ('customerChineseName', '中文名', 'common_compare', {}, 'customerChineseNameResult'), |
| 1065 | ('idNum', '证件号码', 'common_compare', {}), | 1065 | ('idNum', '证件号码', 'common_compare', {}, 'idNumResult'), |
| 1066 | ('idExpiryDate', '有效期限', 'date_compare', {'ocr_split': True, 'input_replace': '.'}), # 2013.10.24-2023.10.23 | 1066 | ('idExpiryDate', '有效期限', 'date_compare', {'ocr_split': True, 'input_replace': '.'}, 'idExpiryDateResult'), # 2013.10.24-2023.10.23 |
| 1067 | ('dateOfBirth', '出生日期', 'date_compare', {'input_replace': '.'}), # 2023.10.23 | 1067 | ('dateOfBirth', '出生日期', 'date_compare', {'input_replace': '.'}, 'dateOfBirthResult'), # 2023.10.23 |
| 1068 | ] | 1068 | ] |
| 1069 | 1069 | ||
| 1070 | # 居住证 | 1070 | # 居住证 |
| 1071 | ITRES = [ | 1071 | ITRES = [ |
| 1072 | ('customerChineseName', '姓名', 'common_compare', {}), | 1072 | ('customerChineseName', '姓名', 'common_compare', {}, 'customerChineseName'), |
| 1073 | ('idNum', '公民身份号码', 'common_compare', {}), | 1073 | ('idNum', '公民身份号码', 'common_compare', {}, 'idNum'), |
| 1074 | ('secondIdNum', '通行证号码', 'common_compare', {}), | 1074 | ('secondIdNum', '通行证号码', 'common_compare', {}, 'secondIdNum'), |
| 1075 | ('idExpiryDate', '有效期限', 'date_compare', {'ocr_split': True, 'input_replace': ''}), # 20200410-20250410 | 1075 | ('idExpiryDate', '有效期限', 'date_compare', {'ocr_split': True, 'input_replace': ''}, 'idExpiryDate'), # 20200410-20250410 |
| 1076 | ('dateOfBirth', '出生年月', 'date_compare', {'input_replace': ''}), # 20231023 | 1076 | ('dateOfBirth', '出生年月', 'date_compare', {'input_replace': ''}, 'dateOfBirth'), # 20231023 |
| 1077 | ] | 1077 | ] |
| 1078 | 1078 | ||
| 1079 | ID_TYPE_COMPARE = { | 1079 | ID_TYPE_COMPARE = { |
| ... | @@ -1090,33 +1090,33 @@ ID_TYPE_COMPARE = { | ... | @@ -1090,33 +1090,33 @@ ID_TYPE_COMPARE = { |
| 1090 | # c)两中比对 均不一致:N,向GCAP发送:车辆登记证 & 行驶证识别结果 | 1090 | # c)两中比对 均不一致:N,向GCAP发送:车辆登记证 & 行驶证识别结果 |
| 1091 | # 车辆登记证 | 1091 | # 车辆登记证 |
| 1092 | PCUSD_MVC = [ | 1092 | PCUSD_MVC = [ |
| 1093 | ('vinNo', '9.车辆识别代号/车架号', 'common_compare', {}), | 1093 | ('vinNo', '9.车辆识别代号/车架号', 'common_compare', {}, 'vinNoResult'), |
| 1094 | ('manufactureDate', '32.车辆出厂日期', 'common_compare', {}), | 1094 | ('manufactureDate', '32.车辆出厂日期', 'common_compare', {}, 'manufactureDateResult'), |
| 1095 | ('firstRegistrationDate', '3.登记日期', 'common_compare', {}), | 1095 | ('firstRegistrationDate', '3.登记日期', 'common_compare', {}, 'firstRegistrationDateResult'), |
| 1096 | ] | 1096 | ] |
| 1097 | 1097 | ||
| 1098 | # 行驶证 | 1098 | # 行驶证 |
| 1099 | PCUSD_DL = [ | 1099 | PCUSD_DL = [ |
| 1100 | ('vinNo', '车辆识别代码', 'common_compare', {}), | 1100 | ('vinNo', '车辆识别代码', 'common_compare', {}, 'vinNoResult'), |
| 1101 | ] | 1101 | ] |
| 1102 | 1102 | ||
| 1103 | # 营业执照 | 1103 | # 营业执照 |
| 1104 | TCCOR = [ | 1104 | TCCOR = [ |
| 1105 | ('customerChineseName', '企业名称', 'common_compare', {}), | 1105 | ('customerChineseName', '企业名称', 'common_compare', {}, 'customerChinessNameResult'), |
| 1106 | ('legalRepName', '经营者姓名', 'name_compare', {}), | 1106 | ('legalRepName', '经营者姓名', 'name_compare', {}, 'legalRepNameResult'), |
| 1107 | ('idNum', '注册号', 'common_compare', {}), | 1107 | ('idNum', '注册号', 'common_compare', {}, 'idNumResult'), |
| 1108 | ('businessLicenseNo', '注册号', 'common_compare', {}), | 1108 | ('businessLicenseNo', '注册号', 'common_compare', {}, 'businessLicenseNoResult'), |
| 1109 | ('taxRegistrationCode', '注册号', 'common_compare', {}), | 1109 | ('taxRegistrationCode', '注册号', 'common_compare', {}, 'taxRegistrationCodeResult'), |
| 1110 | ('incorporationDate', '成立日期', 'date_compare', {'ocr_replace': True}), # 2017年07月11日 | 1110 | ('incorporationDate', '成立日期', 'date_compare', {'ocr_replace': True}, 'incorporationDateResult'), # 2017年07月11日 |
| 1111 | # 2017年07月11日至长期 1. OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0 | 1111 | # 2017年07月11日至长期 1. OCR识别为长期,向GCAP发送:2099-12-31 00:00:00.0 |
| 1112 | ('businessLicenseDueDate', '营业期限', 'date_compare', {'long': True, 'ocr_replace': True}), | 1112 | ('businessLicenseDueDate', '营业期限', 'date_compare', {'long': True, 'ocr_replace': True}, 'businessLicenseDueDateResult'), |
| 1113 | ('capitalRegAmount', '注册资本', 'rmb_compare', {}), # 壹拾万元整 将OCR识别结果(人民币大写)转化为数字 | 1113 | ('capitalRegAmount', '注册资本', 'rmb_compare', {}, 'capitalRegAmountResult'), # 壹拾万元整 将OCR识别结果(人民币大写)转化为数字 |
| 1114 | ] | 1114 | ] |
| 1115 | 1115 | ||
| 1116 | TCSEP = [ | 1116 | TCSEP = [ |
| 1117 | ('companyName', '企业名称', 'common_compare', {}), | 1117 | ('companyName', '企业名称', 'common_compare', {}, 'companyNameResult'), |
| 1118 | ('registeredCapital', '注册资本', 'rmb_compare', {}), # 壹拾万元整 将OCR识别结果(人民币大写)转化为数字 | 1118 | ('registeredCapital', '注册资本', 'rmb_compare', {}, 'registeredCapitalResult'), # 壹拾万元整 将OCR识别结果(人民币大写)转化为数字 |
| 1119 | ('selfEmployedSubType', '企业类型', 'type_compare', {}) # 有限责任公司 | 1119 | ('selfEmployedSubType', '企业类型', 'type_compare', {}, 'selfEmployedSubTypeResult') # 有限责任公司 |
| 1120 | ] | 1120 | ] |
| 1121 | 1121 | ||
| 1122 | # 1. POS数据OCR识别结果对应关系如下: | 1122 | # 1. POS数据OCR识别结果对应关系如下: |
| ... | @@ -1131,7 +1131,7 @@ RESULT_NA = 'NA' | ... | @@ -1131,7 +1131,7 @@ RESULT_NA = 'NA' |
| 1131 | IN_ORDER = ('applicantType', 'idType', 'secondIdType', 'customerType', 'customerChineseName', 'idNum', 'secondIdNum', | 1131 | IN_ORDER = ('applicantType', 'idType', 'secondIdType', 'customerType', 'customerChineseName', 'idNum', 'secondIdNum', |
| 1132 | "idExpiryDate", "dateOfBirth", 'companyName', "registeredCapital", 'selfEmployedSubType',) | 1132 | "idExpiryDate", "dateOfBirth", 'companyName', "registeredCapital", 'selfEmployedSubType',) |
| 1133 | UC_ORDER = ('vinNo', 'manufactureDate', 'firstRegistrationDate') | 1133 | UC_ORDER = ('vinNo', 'manufactureDate', 'firstRegistrationDate') |
| 1134 | CO_ORDER = ('customerChineseName', 'legalRepName', 'idNum', 'businessLicenseNo', 'taxRegistrationCode', | 1134 | CO_ORDER = ('customerChineseName', 'legalRepName', 'idNum', 'customerType', 'businessLicenseNo', 'taxRegistrationCode', |
| 1135 | 'incorporationDate', 'businessLicenseDueDate', 'capitalRegAmount') | 1135 | 'incorporationDate', 'businessLicenseDueDate', 'capitalRegAmount') |
| 1136 | 1136 | ||
| 1137 | 1137 | ... | ... |
| ... | @@ -25,7 +25,7 @@ class GCAP: | ... | @@ -25,7 +25,7 @@ class GCAP: |
| 25 | response = requests.post(self.url, headers=self.headers, data=data, verify=False, auth=self.auth) | 25 | response = requests.post(self.url, headers=self.headers, data=data, verify=False, auth=self.auth) |
| 26 | if response.status_code != 200: | 26 | if response.status_code != 200: |
| 27 | raise GCAPException('GCAP response with code: {0}'.format(response.status_code)) | 27 | raise GCAPException('GCAP response with code: {0}'.format(response.status_code)) |
| 28 | return response.status_code | 28 | return response.text |
| 29 | 29 | ||
| 30 | def test_send(self): | 30 | def test_send(self): |
| 31 | test_res = OrderedDict({ | 31 | test_res = OrderedDict({ | ... | ... |
| ... | @@ -35,22 +35,25 @@ def field_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set): | ... | @@ -35,22 +35,25 @@ def field_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set): |
| 35 | break | 35 | break |
| 36 | for idx, compare_tuple in enumerate(compare_list): | 36 | for idx, compare_tuple in enumerate(compare_list): |
| 37 | input_str = info_dict.get(compare_tuple[0]) | 37 | input_str = info_dict.get(compare_tuple[0]) |
| 38 | ocr_str = ocr_res.get(compare_tuple[1], '') | 38 | ocr_str = ocr_res.get(compare_tuple[1]) |
| 39 | compare_res = getattr(cp, compare_tuple[2])( | 39 | compare_res, ocr_output = getattr(cp, compare_tuple[2])( |
| 40 | info_dict.get(compare_tuple[0]), ocr_res.get(compare_tuple[1]), **compare_tuple[3]) | 40 | info_dict.get(compare_tuple[0]), ocr_res.get(compare_tuple[1]), idx, **compare_tuple[3]) |
| 41 | if idx == 0 and compare_res == consts.RESULT_N: | 41 | if idx == 0 and compare_res == consts.RESULT_N: |
| 42 | break | 42 | break |
| 43 | is_find = True | 43 | is_find = True |
| 44 | info_dict[compare_tuple[0] + 'Result'] = compare_res | 44 | info_dict[compare_tuple[4]] = compare_res |
| 45 | if input_str is not None: | 45 | if input_str is not None: |
| 46 | info_dict[compare_tuple[0]] = ocr_str | 46 | if ocr_str is None or ocr_output is None: |
| 47 | del info_dict[compare_tuple[0]] | ||
| 48 | else: | ||
| 49 | info_dict[compare_tuple[0]] = ocr_output | ||
| 47 | res_set.add(compare_res) | 50 | res_set.add(compare_res) |
| 48 | if not is_find: | 51 | if not is_find: |
| 49 | res_set.add(consts.RESULT_N) | 52 | res_set.add(consts.RESULT_N) |
| 50 | for compare_tuple in compare_list: | 53 | for compare_tuple in compare_list: |
| 51 | info_dict[compare_tuple[0] + 'Result'] = consts.RESULT_NA | 54 | info_dict[compare_tuple[4]] = consts.RESULT_NA |
| 52 | if compare_tuple[0] in info_dict: | 55 | if compare_tuple[0] in info_dict: |
| 53 | info_dict[compare_tuple[0]] = '' | 56 | del info_dict[compare_tuple[0]] |
| 54 | 57 | ||
| 55 | 58 | ||
| 56 | def usedcar_info_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set): | 59 | def usedcar_info_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_set): |
| ... | @@ -66,21 +69,21 @@ def usedcar_info_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_s | ... | @@ -66,21 +69,21 @@ def usedcar_info_compare(info_dict, ocr_res_dict, ocr_field, compare_list, res_s |
| 66 | input_str = info_dict.get(compare_tuple[0]) | 69 | input_str = info_dict.get(compare_tuple[0]) |
| 67 | ocr_str = ocr_res.get(compare_tuple[1], '') | 70 | ocr_str = ocr_res.get(compare_tuple[1], '') |
| 68 | compare_res = getattr(cp, compare_tuple[2])( | 71 | compare_res = getattr(cp, compare_tuple[2])( |
| 69 | info_dict.get(compare_tuple[0]), ocr_res.get(compare_tuple[1]), **compare_tuple[3]) | 72 | info_dict.get(compare_tuple[0]), ocr_res.get(compare_tuple[1]), idx, **compare_tuple[3]) |
| 70 | if idx == 0 and compare_res == consts.RESULT_N: | 73 | if idx == 0 and compare_res == consts.RESULT_N: |
| 71 | no_match_vino.append(ocr_str) | 74 | no_match_vino.append(ocr_str) |
| 72 | break | 75 | break |
| 73 | is_find = True | 76 | is_find = True |
| 74 | info_dict[compare_tuple[0] + 'Result'] = compare_res | 77 | info_dict[compare_tuple[4]] = compare_res |
| 75 | if input_str is not None: | 78 | if input_str is not None: |
| 76 | info_dict[compare_tuple[0]] = ocr_str | 79 | info_dict[compare_tuple[0]] = ocr_str |
| 77 | res_set.add(compare_res) | 80 | res_set.add(compare_res) |
| 78 | if not is_find: | 81 | if not is_find: |
| 79 | res_set.add(consts.RESULT_N) | 82 | res_set.add(consts.RESULT_N) |
| 80 | for compare_tuple in compare_list: | 83 | for compare_tuple in compare_list: |
| 81 | info_dict[compare_tuple[0] + 'Result'] = consts.RESULT_N | 84 | info_dict[compare_tuple[4]] = consts.RESULT_N |
| 82 | if compare_tuple[0] in info_dict: | 85 | if compare_tuple[0] in info_dict: |
| 83 | info_dict[compare_tuple[0]] = '' | 86 | del info_dict[compare_tuple[0]] |
| 84 | return is_find, no_match_vino | 87 | return is_find, no_match_vino |
| 85 | 88 | ||
| 86 | 89 | ||
| ... | @@ -123,7 +126,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -123,7 +126,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
| 123 | 'vehicleStatus': last_obj.vehicle_status, | 126 | 'vehicleStatus': last_obj.vehicle_status, |
| 124 | 'wholeResult': 'Y', | 127 | 'wholeResult': 'Y', |
| 125 | 'wholeResultMessage': '', | 128 | 'wholeResultMessage': '', |
| 126 | 'applicationLink': '', | 129 | 'applicationLink': r'\\china.bmw.corp\WINFS\SF-CN-data\SF3-CN-S\SF3-CN-S-1-New', |
| 127 | } | 130 | } |
| 128 | }) | 131 | }) |
| 129 | 132 | ||
| ... | @@ -165,7 +168,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -165,7 +168,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
| 165 | elif mvc_find is False and dl_find is True: | 168 | elif mvc_find is False and dl_find is True: |
| 166 | vino = mvc_vinos[0] if len(mvc_vinos) > 0 else '' | 169 | vino = mvc_vinos[0] if len(mvc_vinos) > 0 else '' |
| 167 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino | 170 | order_usedcar_info[consts.PCUSD_MVC[0][0]] = vino |
| 168 | order_usedcar_info[consts.PCUSD_MVC[0][0] + 'Result'] = consts.RESULT_N | 171 | order_usedcar_info[consts.PCUSD_MVC[0][4]] = consts.RESULT_N |
| 169 | elif mvc_find is False and dl_find is False: | 172 | elif mvc_find is False and dl_find is False: |
| 170 | vino_list = [] | 173 | vino_list = [] |
| 171 | if len(mvc_vinos) > 0: | 174 | if len(mvc_vinos) > 0: |
| ... | @@ -213,7 +216,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -213,7 +216,7 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
| 213 | try: | 216 | try: |
| 214 | for times in range(consts.RETRY_TIMES): | 217 | for times in range(consts.RETRY_TIMES): |
| 215 | try: | 218 | try: |
| 216 | gcap.send(data) | 219 | res_text = gcap.send(data) |
| 217 | except Exception as e: | 220 | except Exception as e: |
| 218 | gcap_exc = str(e) | 221 | gcap_exc = str(e) |
| 219 | else: | 222 | else: |
| ... | @@ -225,5 +228,8 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): | ... | @@ -225,5 +228,8 @@ def compare(application_id, application_entity, uniq_seq, ocr_res_id): |
| 225 | '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq, | 228 | '[error={5}]'.format(log_base, application_entity, application_id, uniq_seq, |
| 226 | ocr_res_id, traceback.format_exc())) | 229 | ocr_res_id, traceback.format_exc())) |
| 227 | else: | 230 | else: |
| 231 | compare_log.info('{0} [gcap success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}] ' | ||
| 232 | '[response={5}]'.format(log_base, application_entity, application_id, uniq_seq, | ||
| 233 | ocr_res_id, res_text)) | ||
| 228 | compare_log.info('{0} [task success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format( | 234 | compare_log.info('{0} [task success] [entity={1}] [id={2}] [uniq_seq={3}] [ocr_res_id={4}]'.format( |
| 229 | log_base, application_entity, application_id, uniq_seq, ocr_res_id)) | 235 | log_base, application_entity, application_id, uniq_seq, ocr_res_id)) | ... | ... |
| 1 | import re | 1 | import re |
| 2 | from datetime import datetime | ||
| 2 | from .rmb_upper import to_rmb_upper | 3 | from .rmb_upper import to_rmb_upper |
| 3 | 4 | ||
| 4 | 5 | ||
| ... | @@ -33,14 +34,14 @@ class Comparison: | ... | @@ -33,14 +34,14 @@ class Comparison: |
| 33 | else: | 34 | else: |
| 34 | return self.RESULT_N | 35 | return self.RESULT_N |
| 35 | 36 | ||
| 36 | def common_compare(self, input_str, ocr_str, **kwargs): | 37 | def common_compare(self, input_str, ocr_str, idx, **kwargs): |
| 37 | if not isinstance(input_str, str) or not isinstance(ocr_str, str): | 38 | if not isinstance(input_str, str) or not isinstance(ocr_str, str): |
| 38 | return self.RESULT_N | 39 | return self.RESULT_N |
| 39 | return self.build_res(input_str == ocr_str) | 40 | return self.build_res(input_str == ocr_str), ocr_str |
| 40 | 41 | ||
| 41 | def name_compare(self, input_str, ocr_str, **kwargs): | 42 | def name_compare(self, input_str, ocr_str, idx, **kwargs): |
| 42 | if not isinstance(input_str, str) or not isinstance(ocr_str, str): | 43 | if not isinstance(input_str, str) or not isinstance(ocr_str, str): |
| 43 | return self.RESULT_N | 44 | return self.RESULT_N, ocr_str |
| 44 | if kwargs.get('is_passport'): | 45 | if kwargs.get('is_passport'): |
| 45 | input_obj = re.search(r'[a-zA-Z]]!', input_str) | 46 | input_obj = re.search(r'[a-zA-Z]]!', input_str) |
| 46 | if input_obj: | 47 | if input_obj: |
| ... | @@ -48,39 +49,46 @@ class Comparison: | ... | @@ -48,39 +49,46 @@ class Comparison: |
| 48 | ocr_obj = re.search(r'[a-zA-Z]]!', ocr_str) | 49 | ocr_obj = re.search(r'[a-zA-Z]]!', ocr_str) |
| 49 | if ocr_obj: | 50 | if ocr_obj: |
| 50 | ocr_s = ocr_obj.group() | 51 | ocr_s = ocr_obj.group() |
| 51 | return self.build_res(input_s == ocr_s) | 52 | return self.build_res(input_s == ocr_s), ocr_str |
| 52 | return self.RESULT_N | 53 | return self.RESULT_N, ocr_str |
| 53 | else: | 54 | else: |
| 54 | return self.build_res((input_str == ocr_str)) | 55 | return self.build_res((input_str == ocr_str)), ocr_str |
| 55 | else: | 56 | else: |
| 56 | if re.search(r'[a-zA-Z]]', input_str): | 57 | if re.search(r'[a-zA-Z]]', input_str): |
| 57 | return self.RESULT_NA | 58 | return self.RESULT_NA, ocr_str |
| 58 | input_s = input_str.translate(self.TRANS) | 59 | input_s = input_str.translate(self.TRANS) |
| 59 | ocr_s = ocr_str.translate(self.TRANS) | 60 | ocr_s = ocr_str.translate(self.TRANS) |
| 60 | return self.build_res(input_s == ocr_s) | 61 | return self.build_res(input_s == ocr_s), ocr_str |
| 61 | 62 | ||
| 62 | def date_compare(self, input_str, ocr_str, **kwargs): | 63 | def date_compare(self, input_str, ocr_str, idx, **kwargs): |
| 63 | if not isinstance(input_str, str) or not isinstance(ocr_str, str): | 64 | if not isinstance(input_str, str) or not isinstance(ocr_str, str): |
| 64 | return self.RESULT_N | 65 | return self.RESULT_N, ocr_str |
| 65 | if kwargs.get('long', False) and '长期' in ocr_str: | 66 | if kwargs.get('long', False) and '长期' in ocr_str: |
| 66 | return '2099-12-31' | 67 | return self.RESULT_Y, '2099-12-31' |
| 67 | if kwargs.get('ocr_split', False): | 68 | if kwargs.get('ocr_split', False): |
| 68 | ocr_str = ocr_str.split('-')[-1] | 69 | ocr_str = ocr_str.split('-')[-1] |
| 69 | if kwargs.get('ocr_replace', False): | 70 | if kwargs.get('ocr_replace', False): |
| 70 | ocr_str = ocr_str.replace('年', '-').replace('月', '-').replace('日', '') | 71 | ocr_str = ocr_str.replace('年', '-').replace('月', '-').replace('日', '') |
| 71 | if kwargs.get('input_replace') is not None: | 72 | if kwargs.get('input_replace') is not None: |
| 72 | input_str = input_str.replace('-', kwargs.get('input_replace')) | 73 | input_str = input_str.replace('-', kwargs.get('input_replace')) |
| 73 | return self.build_res(input_str == ocr_str) | 74 | try: |
| 75 | ocr_output = datetime.strptime(ocr_str, '%Y{0}%m{0}%d'.format( | ||
| 76 | kwargs.get('input_replace'))).strftime('%Y-%m-%d') | ||
| 77 | except Exception as e: | ||
| 78 | ocr_output = None | ||
| 79 | else: | ||
| 80 | ocr_output = ocr_str | ||
| 81 | return self.build_res(input_str == ocr_str), ocr_output | ||
| 74 | 82 | ||
| 75 | def rmb_compare(self, input_str, ocr_str, **kwargs): | 83 | def rmb_compare(self, input_str, ocr_str, idx, **kwargs): |
| 76 | if not isinstance(input_str, str) or not isinstance(ocr_str, str): | 84 | if not isinstance(input_str, str) or not isinstance(ocr_str, str): |
| 77 | return self.RESULT_N | 85 | return self.RESULT_N |
| 78 | input_rmb_upper = to_rmb_upper(float(input_str)) | 86 | input_rmb_upper = to_rmb_upper(float(input_str)) |
| 79 | return self.build_res(input_rmb_upper == ocr_str) | 87 | return self.build_res(input_rmb_upper == ocr_str), input_str |
| 80 | 88 | ||
| 81 | def type_compare(self, input_str, ocr_str, **kwargs): | 89 | def type_compare(self, input_str, ocr_str, idx, **kwargs): |
| 82 | if not isinstance(input_str, str) or not isinstance(ocr_str, str): | 90 | if not isinstance(input_str, str) or not isinstance(ocr_str, str): |
| 83 | return self.RESULT_N | 91 | return self.RESULT_N, ocr_str |
| 84 | for map_tuple in self.TYPE_MAPPING: | 92 | for map_tuple in self.TYPE_MAPPING: |
| 85 | if re.search(map_tuple[0], ocr_str) is not None: | 93 | if re.search(map_tuple[0], ocr_str) is not None: |
| 86 | compare_str = map_tuple[1] | 94 | compare_str = map_tuple[1] |
| ... | @@ -88,7 +96,7 @@ class Comparison: | ... | @@ -88,7 +96,7 @@ class Comparison: |
| 88 | else: | 96 | else: |
| 89 | compare_str = self.CSOTH | 97 | compare_str = self.CSOTH |
| 90 | 98 | ||
| 91 | return self.build_res(input_str == compare_str) | 99 | return self.build_res(input_str == compare_str), ocr_str |
| 92 | 100 | ||
| 93 | 101 | ||
| 94 | cp = Comparison() | 102 | cp = Comparison() | ... | ... |
-
Please register or sign in to post a comment