ai_repair_data
This commit is contained in:
@@ -18,6 +18,19 @@ from app.common.elastic_helper import ElasticHelper
|
||||
##--------------------------------
|
||||
# لازم است این فیلد پرشود تا مجلس بتواند دسترسی تغییر داشته باشد
|
||||
##------------------------------------
|
||||
def is_section_empty(section_path):
|
||||
filtered_keys = ['فصل','موخره','امضاء','عنوان']
|
||||
if '>' in section_path:
|
||||
path_parts = section_path.split('>')
|
||||
for key in filtered_keys:
|
||||
if key in path_parts[-1]:
|
||||
return True
|
||||
else:
|
||||
for key in filtered_keys:
|
||||
if key in section_path:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def repair_ai_codes( elastic, index_name_i, index_name_o, file_log) :
|
||||
body = {}
|
||||
@@ -45,6 +58,55 @@ def repair_ai_codes( elastic, index_name_i, index_name_o, file_log) :
|
||||
qanon_id = entry.get("qanon_id", "")
|
||||
other_info = entry.get("other_info", {})
|
||||
|
||||
code_ai = entry.get("code-ai", {})
|
||||
tcode = entry.get("tcode", {})
|
||||
|
||||
body = {}
|
||||
history_codes = []
|
||||
if other_info and is_section_empty(other_info['full_path']) :
|
||||
body['code-ai'] = {}
|
||||
else :
|
||||
if code_ai :
|
||||
history_codes.append({
|
||||
"version_key": "D54_v1",
|
||||
"sub_key": "main",
|
||||
"label": text_normal.normalize_qanon(code_ai['label']),
|
||||
"score": code_ai['score'],
|
||||
})
|
||||
|
||||
|
||||
if tcode :
|
||||
for item in tcode['mains_old'] :
|
||||
history_codes.append({
|
||||
"version_key": "TH40_V1",
|
||||
"sub_key": "main",
|
||||
"label": text_normal.normalize_qanon(item)
|
||||
})
|
||||
|
||||
for item in tcode['subs_old'] :
|
||||
history_codes.append({
|
||||
"version_key": "TH40_V1",
|
||||
"sub_key": "sub",
|
||||
"label": text_normal.normalize_qanon(item)
|
||||
})
|
||||
|
||||
for item in tcode['mains'] :
|
||||
history_codes.append({
|
||||
"version_key": "TH54_V1",
|
||||
"sub_key": "main",
|
||||
"label": text_normal.normalize_qanon(item)
|
||||
})
|
||||
|
||||
for item in tcode['subs'] :
|
||||
history_codes.append({
|
||||
"version_key": "TH54_V1",
|
||||
"sub_key": "sub",
|
||||
"label": text_normal.normalize_qanon(item)
|
||||
})
|
||||
|
||||
body['tcode'] = {}
|
||||
|
||||
|
||||
ai_code = entry.get("ai_code", {})
|
||||
ai_codes = entry.get("ai_codes", [])
|
||||
#----------------------------------------------
|
||||
@@ -63,15 +125,22 @@ def repair_ai_codes( elastic, index_name_i, index_name_o, file_log) :
|
||||
ai_code["label"] = label
|
||||
#----------------------------------------------
|
||||
|
||||
body = {}
|
||||
if other_info.full_path == 'عنوان' or other_info.full_path=='موخره' or other_info.full_path=='امضاء' :
|
||||
body = {}
|
||||
if other_info and is_section_empty(other_info['full_path']) :
|
||||
body = {
|
||||
'ai_code': {},
|
||||
'ai_codes': []
|
||||
}
|
||||
else:
|
||||
if ai_code :
|
||||
body['ai_code'] = ai_code
|
||||
if ai_codes :
|
||||
body['ai_codes'] = ai_codes
|
||||
|
||||
# print(history_codes)
|
||||
|
||||
if history_codes :
|
||||
body['history_codes'] = history_codes
|
||||
|
||||
if not body :
|
||||
continue
|
||||
|
||||
@@ -85,7 +154,7 @@ def repair_ai_codes( elastic, index_name_i, index_name_o, file_log) :
|
||||
i=i+1
|
||||
|
||||
|
||||
if len(bulk_data) >= 100:
|
||||
if len(bulk_data) >= 200:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + qanon_id)
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
|
||||
Reference in New Issue
Block a user