import_codes_to_list
This commit is contained in:
+23
-12
@@ -49,6 +49,14 @@ def get_qanon_title_sample(text):
|
||||
text = re.sub(r"( |\u200C)+", "", text)
|
||||
return text
|
||||
|
||||
def get_section_title_sample(text):
|
||||
text = text_normalizer.normalize_search_qanon(text)
|
||||
text = text_normalizer.remove_arabic_diacritics(text)
|
||||
text = text_normalizer.hamzah_normal(text)
|
||||
text = text_normalizer.alaem_normal(text)
|
||||
text = re.sub(r"( |\u200C|\>|\<|-|ـ)+", "", text)
|
||||
return text
|
||||
|
||||
def searchSectionId(elastic, index_name, qanon_id, section_title):
|
||||
score = 100
|
||||
body = {
|
||||
@@ -73,12 +81,12 @@ def searchSectionId(elastic, index_name, qanon_id, section_title):
|
||||
}
|
||||
}
|
||||
s_res = elastic.es.search(index=index_name, body=body)
|
||||
section_title = re.sub(r"( |\u200C|\>|\<)+", "", section_title)
|
||||
section_title = get_section_title_sample(section_title)
|
||||
for item in s_res["hits"]["hits"]:
|
||||
other_info = item['_source']['other_info']
|
||||
title = other_info['full_path']
|
||||
# حذف اضافات
|
||||
title = re.sub(r"( |\u200C|\>|\<|-|ـ)+", "", title)
|
||||
title = get_section_title_sample(title)
|
||||
|
||||
if title == section_title :
|
||||
return item["_id"], 100, item
|
||||
@@ -191,7 +199,7 @@ def importDataToElastic(elastic, file_excel, index_name_o, tcode, file_log, resu
|
||||
column_names = df.columns.tolist()
|
||||
print(column_names)
|
||||
|
||||
file = open(file_log, 'w', encoding='utf8')
|
||||
file = open(file_log, 'w+', encoding='utf8')
|
||||
|
||||
dict_qanon_id = get_dict_qanon_title("qanon_title_ids.txt")
|
||||
# Print the list of rows
|
||||
@@ -267,11 +275,6 @@ def importDataToElastic(elastic, file_excel, index_name_o, tcode, file_log, resu
|
||||
if result_path == '' :
|
||||
directory_path = os.path.dirname(file_excel)
|
||||
result_path = directory_path + "/result/"
|
||||
|
||||
try:
|
||||
os.makedirs(result_path, exist_ok=True)
|
||||
except Exception as e:
|
||||
print(result_path)
|
||||
|
||||
file_name = os.path.basename(file_excel)
|
||||
file_excel2 = result_path + file_name.replace('.xlsx', '_result.xlsx')
|
||||
@@ -301,10 +304,15 @@ def run_in_directory(elastic, directory, output):
|
||||
for file in files :
|
||||
file_name = os.path.basename(file)
|
||||
code_name = os.path.splitext(file_name)[0]
|
||||
log_file = output + "/log_r_"+code_name+".txt"
|
||||
w1 = text_normalizer.split_words(code_name)[0]
|
||||
log_file = output + "/log_r_"+w1+".txt"
|
||||
file_path = os.path.join(directory, file)
|
||||
try:
|
||||
os.makedirs(output, exist_ok=True)
|
||||
except Exception as e:
|
||||
print(output)
|
||||
|
||||
# importDataToElastic(elastic, file_path, "mj_qa_section", code_name, log_file)
|
||||
importDataToElastic(elastic, file_path, "mj_qa_section", code_name, log_file)
|
||||
|
||||
|
||||
|
||||
@@ -321,9 +329,9 @@ path_base_map = "G:/Project2/gateway2_main/repo/_other/"
|
||||
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||
|
||||
|
||||
# run_in_directory(elastic, "./data/tcodes", "./data/tcodes/result")
|
||||
run_in_directory(elastic, "./data/tcodes", "./data/tcodes/result")
|
||||
|
||||
importDataToElastic(elastic, "./data/tcodes/مسکن و شهرسازی.xlsx", "mj_qa_section", "مسکن و شهرسازی", "./data/log_r3.txt")
|
||||
# importDataToElastic(elastic, "./data/tcodes/مسکن و شهرسازی.xlsx", "mj_qa_section", "مسکن و شهرسازی", "./data/log_r3.txt")
|
||||
# importDataToElastic(elastic, "./data/tcodes/آمار، برنامه و بودجه.xlsx", "mj_qa_section", "مسکن و شهرسازی", "./data/log_r_آمار.txt")
|
||||
# importDataToElastic(elastic, "./data/tcodes/آیین دادرسی مدنی.xlsx", "mj_qa_section", "مسکن و شهرسازی", "./data/log_r_دادرسی.txt")
|
||||
# importDataToElastic(elastic, "./data/tcodes/نفت و گاز.xlsx", "mj_qa_section", "مسکن و شهرسازی", "./data/log_r_نفت.txt")
|
||||
@@ -337,6 +345,9 @@ importDataToElastic(elastic, "./data/tcodes/مسکن و شهرسازی.xlsx", "m
|
||||
# text="قانون تشکیلات، وظایف و انتخابات شوراهای اسلامی کشور و انتخاب شهرداران مصوب 1/3/1375 و اصلاحات بعدی آن"
|
||||
text="قانون بودجه سال 1369کل کشور"
|
||||
|
||||
text="پیوست 3>متن >ضمیمه 1>قسمت الف>فصل پنجم>جدول الف-1-1-1 /5"
|
||||
# searchSectionId(elastic, "mj_qa_section", "qq240970", text )
|
||||
|
||||
# text = text_normalizer.date_correction(text)
|
||||
# text = re.sub(r"(\d+?) /(\d+?) /(\d+?)", r"\1/\2/\3", text)
|
||||
# text = re.sub(r"(\d)/(\d)/(\d{4})", r"0\1/0\2/\3", text)
|
||||
|
||||
Reference in New Issue
Block a user