From 984ccdf9dad400f950bc7dcd6ab37b0ddc58a27f Mon Sep 17 00:00:00 2001 From: init_mahdi Date: Mon, 22 Sep 2025 16:34:49 +0330 Subject: [PATCH] anlyzes update to elastic search --- .gitignore | 1 + app/for_ai/codes_tokens.py | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index de117f4..ce4b63c 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ yarn-error.log* *.sw? *.rar *.zip +analyzed_domains.json diff --git a/app/for_ai/codes_tokens.py b/app/for_ai/codes_tokens.py index ce9dd89..2e0fc8c 100644 --- a/app/for_ai/codes_tokens.py +++ b/app/for_ai/codes_tokens.py @@ -206,19 +206,21 @@ def extract_domain_words( final_structure = {} all_code_labels = list(json_input_data.keys()) - # برای هر عنوان اصلی for code_label in all_code_labels: + if code_label == 'سایر': + continue + current_words_dict = json_input_data[code_label] + code_label = text_normalizer.normalize_qanon(code_label) - if not code_label in dict_domain_id : + if not code_label in dict_domain_id: print( "------------ error ", item ) continue domain_id = dict_domain_id[code_label] code_label_id = domain_type + "_" + domain_id - current_words_dict = json_input_data[code_label] # 1. words_general — تمام کلمات این عنوان — مرتب بر اساس تکرار @@ -266,15 +268,17 @@ def extract_domain_words( list_code_words = [] for other_title in all_code_labels: - if other_title == code_label: + other_words = set(json_input_data[other_title].keys()) + current_words = set(current_words_dict.keys()) + + other_title = text_normalizer.normalize_qanon(other_title) + + if (other_title == code_label) or (other_title =='سایر'): continue - other_words = set(json_input_data[other_title].keys()) - current_words = set(current_words_dict.keys()) - other_title = text_normalizer.normalize_qanon(other_title) - if not other_title in dict_domain_id : + if not (other_title in dict_domain_id): print( "========================= error ", other_title ) continue @@ -323,11 +327,15 @@ def extract_domain_words( final_structure[code_label] = data eid = code_label_id + print(f'data Created! {eid}') try: resp = elastic.update_index_doc(True, index_name_o, eid, data) except Exception as e: - pass + import traceback + print(traceback.print_exc()) + print(f'data NOT saved in es') + print(f'data saved in es') # ذخیره خروجی نهایی with open("./analyzed_domains.json", "w", encoding="utf-8") as f: @@ -353,4 +361,6 @@ path_base_map = "G:/Project2/gateway2_main/repo/_other/" elastic = ElasticHelper(host, password, "elastic", path_base_map) -final_domain_words = extract_domain_words("data/ai/corrected_sorted1.json", elastic, "mj_qa_doamin") +final_domain_words = extract_domain_words(r"C:\Users\TAVASI-3\Desktop\init_mahdi\project\bank_words_per\data\corrected_sorted1.json", elastic, "mj_qa_domain") +# final_domain_words = extract_domain_words("data/ai/corrected_sorted1.json", elastic, "mj_qa_doamin") +# python -m app.for_ai.codes_tokens