From 7140efa3f0c08619d6e1ac57f4ea6204e3ab7d23 Mon Sep 17 00:00:00 2001 From: hsafaei Date: Mon, 22 Sep 2025 15:34:52 +0330 Subject: [PATCH] codes_tokens --- app/for_ai/codes_tokens.py | 203 +++++++++++------ app/for_ai/domains_list.json | 410 ----------------------------------- app/temp_codes.py | 173 +++++++-------- 3 files changed, 213 insertions(+), 573 deletions(-) delete mode 100644 app/for_ai/domains_list.json diff --git a/app/for_ai/codes_tokens.py b/app/for_ai/codes_tokens.py index 1ecbc49..ce9dd89 100644 --- a/app/for_ai/codes_tokens.py +++ b/app/for_ai/codes_tokens.py @@ -1,18 +1,11 @@ import io -import json import os +import json +from collections import defaultdict from dotenv import load_dotenv -# from app.common.text_normalizer import TextNormalizer -# from app.common.elastic_helper import ElasticHelper +from app.common.text_normalizer import TextNormalizer +from app.common.elastic_helper import ElasticHelper -# load_dotenv(dotenv_path='config.env') - - -# host=os.getenv('HOST_160') -# password=os.getenv('HOST_160_PASS') - -# path_base_map = "G:/Project2/gateway2_main/repo/_other/" -# elastic = ElasticHelper(host, password, "elastic", path_base_map) stopwords_fr_sr = "و،شده،از,در,به,را,که,چه,با,تا,بر,ما,شما,ایشان,من,تو,او,وی,انان,آنان,انها,آنها,ان,آن,این,كنيد,است,باشد,بكند,بود,بكنيد,بشود,دارد,داريد,داريم,آمد,آورد,آيد,آيند,باشند,باشيد,بخواهند,برود,بروند,بگيرند,بوديم,بيايد,توانست,توانند,داد,دانيم,خواهيد,ديد,شماريم,شويم,كرد,كرديد,كند,كنند,كنيم,كوچك,نداريم,نكرديد,نكند,نيامد,نيست,نيستيم,هست,هستند,محتاجيم,شود,کنيد,تركيب,هستيم,دود,دارم,ندارد,بگيريد,تبديل,فرموديد,بگيريم,برسد,بگيرد,بوديد,توانستيد,داديد,كنم,نباشيم,ببينيد,شد,آمدند,باشيم,ببينيم,بپذيريم,بتوانند,بتوانيم,بدهد,بدهند,بدهيم,بردارد,برسانيم,بشناسند,بفرمائيد,بكنند,بگوييد,بگوييم,دهد,تواند,گيرد,مي‏شود,آوردند,توانيم,پردازيم,اميدوارم,بينند,بينيد,توانيد,خوانيم,دانم,دانند,دهم,شناسند,فهمد,گوئيم,گويند,گوييم,نمايد,پذيرد,خواهد,نداشت,نبود,نيستند,داديم,بشناسد,رويم,بيند,گذاريد,گويد,ساخت,هر,گرچه,بنابراين,آنچه,آنكه,ابتداء,اينها,يعني,البته,چطور,با,چرا,که,چند,چون,چه,چي,يا,يك,ها,به,بر,آن,از,را,و,كه,براي,در,درباره,بعد,بلكه,تا,پس,آنگاه,اينجا,جلوتر,همان,آخر,الان,ديگر,امروز,هميشگي,هم,همه,همين,هيچ,همينگونه,وقتي,حداقل,منتها,ابتدا,توي,بعضي,بسيار,بي,لازم,مبادا,مكان,كسي,طرف,زمان,بايد,آيا,اين,شما,حالا,خودش,اينكه,ما,آنجا,اگر,زير,خود,فقط,خودشان,يک,من,آنها,خودمان,بنده,اما,او,ايشان,شناختن,آوردن,آمدن,كردن,بودن,است,بود,شد,شود,باشد,باید,شاید,هست,نیست,نبود,می,این,آن,آنجا,یک,حالا,دیگر,یعنی,یکی,دراین,درآن,بعدا,اش,هم,برای,کنیم,اگر,میشود,نپذیرفت,ندارد,ندارید,نداریم,نداند,نکرده,نیز,هستید,هستیم,همانطور,همه,هیچگونه,كرده,بوديد,اما,نباید,میتواند,میشود,ناظر,نمیتوانیم,نمیخواهیم,نمیخورد,نمیشویم,نمیگوییم,مي,حجت الاسلام,حجت الاسلام و المسلمین,حجةالاسلام و المسلمین,حجةالاسلام,والمسلمین,میکند,آیا,ایا,ايا,حجت الاسلام والمسلمین, پیدا ميکند,پیدا,پيدا,اقتضاء انشاء فعلیت" stopwords_fr_ext = "ابی,ارش,است,الف,امی,ان,انجام,انرا,انکه,اول,ای,ب ,باو,برات,بردن,برنامه,بطور,بند,به,بوده,بیبی,بین,پ ,پنج,پنجم,ت ,تبصره,تلف,تمام,تواند,توجه,توسط,جرائم,چهار,حد,خواه,خواهند,داده,داشت,داشته,دم,ده,دو,دوم,دیگری,ذی,رد,رسیدگی,روز,روز ,سایر,سه,سوم,سی,شدن,شش,شود,شوند,صورت,صورتی,صورتیکه,عدم,علیه,عین,غیر,قانون,قانونی,قبل,قرار,قضایی,قوانین,کس,کل,کننده,که,گاه,گردد,ماده,ماده ,ماه,مثل,مقررات,مگر,مگر ,موارد,مواردی,مورد,می,میبرد,میتواند,میشود,میکند,میگردد,نباشد,نباشد ,نخواهد,نداشته,نشود,نصبت,نظر,نفر,نمایند,نمی,نمیشود,نیز,نیز ,های,وارد,وارده,واقع,ولی,وی,یکی" @@ -56,26 +49,26 @@ def word_ignore(word, unwanted_char=UNWANTED_CHAR, unwanted_word=UNWANTED_WORD): return False -def import_words( +def extract_domain_words( json_path, elastic=None, index_name_o=None, ) : with open(json_path, "r", encoding="utf-8") as f: - data = json.load(f) + json_input_data = json.load(f) # with open(output_file, "r", encoding="utf-8") as f: # data2 = json.load(f) # print( - # f'input {len(data)}\n', + # f'input {len(json_input_data)}\n', # f'Output {len(data2)}\n', # ) - print(f'data1_misteral {len(data)}') + print(f'data1_misteral {len(json_input_data)}') # # فیلتر کردن: فقط کلماتی که word_ignore براشون False برمی‌گردونه - # فرض: داده‌های شما در متغیر `data` هست + # فرض: داده‌های شما در متغیر `json_input_data` هست # filtered_words = [] # for item in data1_misteral: @@ -120,7 +113,7 @@ def import_words( # print(f'filtered_inner {len(filtered_inner)}') # new_file[title] = filtered_inner ########################################################################### - # فرض: داده شما در متغیر data هست + # فرض: داده شما در متغیر json_input_data هست # sorted_data = {} # for title, inner_dict in data2_claened.items(): @@ -136,13 +129,13 @@ def import_words( # from collections import OrderedDict # # --- یافتن کلمات مشترک در همه عناوین --- - # all_titles = list(data.keys()) - # if not all_titles: + # all_code_labels = list(json_input_data.keys()) + # if not all_code_labels: # common_words = set() # else: - # common_words = set(data[all_titles[0]].keys()) - # for title in all_titles[1:]: - # common_words &= set(data[title].keys()) + # common_words = set(json_input_data[all_code_labels[0]].keys()) + # for title in all_code_labels[1:]: + # common_words &= set(json_input_data[title].keys()) # # --- جمع‌آوری داده‌ها --- # result = {} @@ -150,8 +143,8 @@ def import_words( # for word in common_words: # title_repeat = {} # دیکشنری تکرار در عناوین # total = 0 - # for title in all_titles: - # count = data[title][word] + # for title in all_code_labels: + # count = json_input_data[title][word] # title_repeat[title] = count # total += count @@ -177,7 +170,7 @@ def import_words( # # ذخیره اطلاعات کلمه: کدام عنوان و چه تعداد # word_info = {} - # for title, inner_dict in data.items(): + # for title, inner_dict in json_input_data.items(): # for word, count in inner_dict.items(): # word_title_count[word] += 1 # # اگر کلمه قبلاً دیده نشده، اطلاعاتش رو ذخیره کن @@ -197,25 +190,53 @@ def import_words( # ) ########################################################################### - import json - from collections import defaultdict + + domain_type = "D51_v1" + text_normalizer = TextNormalizer() + with open("data/ai/domains_list.json", "r", encoding="utf-8") as file: + domains_list = json.load(file) + dict_domain_id = {} + labels_list = [] + for item in domains_list[domain_type] : + item["domain_name"] = text_normalizer.normalize_qanon(item["domain_name"]) + labels_list.append(item["domain_name"]) + dict_domain_id[item["domain_name"]] = str(item["id"]) + final_structure = {} - all_titles = list(data.keys()) + all_code_labels = list(json_input_data.keys()) # برای هر عنوان اصلی - for current_title in all_titles: - current_words_dict = data[current_title] + for code_label in all_code_labels: + + code_label = text_normalizer.normalize_qanon(code_label) + 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 — تمام کلمات این عنوان — مرتب بر اساس تکرار - words_general = dict( - sorted(current_words_dict.items(), key=lambda x: x[1], reverse=True) - ) + list_words_general = [] + count = 1 + for word, value in sorted(current_words_dict.items(), key=lambda x: x[1], reverse=True) : + if count > 1000 : + break + count += 1 + list_words_general.append({ + "word" : word, + "count" : value + }) + # 2. words_own — کلمات منحصربه‌فرد (فقط در این عنوان وجود دارند) word_title_count = defaultdict(int) - for title, inner in data.items(): + for title, inner in json_input_data.items(): for word in inner.keys(): word_title_count[word] += 1 @@ -224,66 +245,112 @@ def import_words( for word, count in current_words_dict.items() if word_title_count[word] == 1 } - words_own = dict( - sorted(words_own.items(), key=lambda x: x[1], reverse=True) - ) + + list_own_words = [] + count = 1 + for word, value in sorted(words_own.items(), key=lambda x: x[1], reverse=True): + if count > 1000 : + break + count += 1 + list_own_words.append({ + "word" : word, + "count" : value + }) + + # 3. word_codes — مقایسه با سایر عناوین word_codes = [] # جمع‌آوری اطلاعات مقایسه برای مرتب‌سازی بعدی - comparisons = [] + list_code_words = [] - for other_title in all_titles: - if other_title == current_title: + for other_title in all_code_labels: + if other_title == code_label: continue + - other_words = set(data[other_title].keys()) + 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 : + print( "========================= error ", other_title ) + continue + + other_doamion_id = dict_domain_id[other_title] + + shared_words = current_words & other_words diff_words = current_words - other_words + union_words = [] + for word in sorted(shared_words, key=lambda w: current_words_dict[w], reverse=True) : + union_words.append({ + "word" : word, + "count" : current_words_dict[word] + }) + + delta_words = [] + for word in sorted(diff_words, key=lambda w: current_words_dict[w], reverse=True) : + delta_words.append({ + "word" : word, + "count" : current_words_dict[word] + }) + + + domain_id = dict_domain_id[code_label] # ساختار داده‌های مقایسه comp_data = { "domain_name": other_title, + "domain_id": other_doamion_id, "shared_count": len(shared_words), - "words_union": { - word: current_words_dict[word] - for word in sorted(shared_words, key=lambda w: current_words_dict[w], reverse=True) - }, - "words_delta": { - word: current_words_dict[word] - for word in sorted(diff_words, key=lambda w: current_words_dict[w], reverse=True) - } + "union_words": union_words, + "delta_words": delta_words } - comparisons.append(comp_data) + list_code_words.append(comp_data) # ✅ مرتب‌سازی مقایسه‌ها بر اساس تعداد کلمات مشترک (نزولی) - comparisons.sort(key=lambda x: x["shared_count"], reverse=True) - - # حذف فیلد موقت shared_count - for comp in comparisons: - comp.pop("shared_count") - - word_codes = comparisons - + list_code_words.sort(key=lambda x: x["shared_count"], reverse=True) + + + data = { + "general_words": list_words_general, + "own_words": list_own_words, + "code_words": list_code_words + } # ✅ ساختار نهایی برای این عنوان - final_structure[current_title] = { - "words_general": words_general, - "words_own": words_own, - "word_codes": word_codes - } - + final_structure[code_label] = data + + eid = code_label_id + try: + resp = elastic.update_index_doc(True, index_name_o, eid, data) + + except Exception as e: + pass + # ذخیره خروجی نهایی with open("./analyzed_domains.json", "w", encoding="utf-8") as f: json.dump(final_structure, f, ensure_ascii=False, indent=2) - + print(f"✅ تحلیل برای {len(final_structure)} عنوان انجام و ذخیره شد.") + return final_structure ########################################################################### -import_words(json_path = json_path) -# list_ = split_str_to_list(in_text=stopwords_fr_sr) -# print(f'list_ {list_}') + + +load_dotenv(dotenv_path='config.env') + +host=os.getenv('HOST_160') +password=os.getenv('HOST_160_PASS') + +# host=os.getenv('HOST_113') +# password=os.getenv('HOST_113_PASS') + +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") diff --git a/app/for_ai/domains_list.json b/app/for_ai/domains_list.json deleted file mode 100644 index 7e27f05..0000000 --- a/app/for_ai/domains_list.json +++ /dev/null @@ -1,410 +0,0 @@ -{ - "D51_v1": [ - { - "domain_name": "اموال و معاملات دولتی", - "id": 8 - }, - { - "domain_name": "تجارت", - "id": 19 - }, - { - "domain_name": "اطلاعات و امنیت", - "id": 9 - }, - { - "domain_name": "حمل و نقل", - "id": 26 - }, - { - "domain_name": "محیط زیست", - "id": 39 - }, - { - "domain_name": "پولی و مالی", - "id": 17 - }, - { - "domain_name": "امور زیربنایی", - "id": 10 - }, - { - "domain_name": "آیین دادرسی کیفری", - "id": 6 - }, - { - "domain_name": "محاسبات عمومی", - "id": 38 - }, - { - "domain_name": "مسکن و شهرسازی", - "id": 41 - }, - { - "domain_name": "ایثـارگران", - "id": 13 - }, - { - "domain_name": "آیین دادرسی مدنی و اداری", - "id": 5 - }, - { - "domain_name": "تعزیرات حکومتی", - "id": 23 - }, - { - "domain_name": "نظامی و انتظامی", - "id": 49 - }, - { - "domain_name": "تشکیلات و امور اداری قوه قضائیه", - "id": 21 - }, - { - "domain_name": "آموزش عالی، پژوهش و فناوری", - "id": 4 - }, - { - "domain_name": "اداری و استخدامی", - "id": 7 - }, - { - "domain_name": "میراث فرهنگی و گردشگری", - "id": 46 - }, - { - "domain_name": "مناطق آزاد و ویژه اقتصادی", - "id": 45 - }, - { - "domain_name": "کشاورزی و دامپروری", - "id": 34 - }, - { - "domain_name": "کار", - "id": 33 - }, - { - "domain_name": "آمار، برنامه و بودجه", - "id": 2 - }, - { - "domain_name": "تشکل‌های مدنی و احزاب", - "id": 20 - }, - { - "domain_name": "فرهنگ و هنر", - "id": 32 - }, - { - "domain_name": "صنعـت", - "id": 30 - }, - { - "domain_name": "آب", - "id": 1 - }, - { - "domain_name": "بانکداری", - "id": 14 - }, - { - "domain_name": "کیفـری", - "id": 35 - }, - { - "domain_name": "مصرف", - "id": 42 - }, - { - "domain_name": "رسانه", - "id": 28 - }, - { - "domain_name": "مـدنـی", - "id": 40 - }, - { - "domain_name": "مالکیت فکری", - "id": 36 - }, - { - "domain_name": "نظام قانون‌گذاری", - "id": 47 - }, - { - "domain_name": "منابع طبیعی", - "id": 44 - }, - { - "domain_name": "اوقاف، اماکن دینی و امور مذهبی", - "id": 12 - }, - { - "domain_name": "فناوری اطلاعات و ارتباطات", - "id": 31 - }, - { - "domain_name": "معـدن", - "id": 43 - }, - { - "domain_name": "مالیات", - "id": 37 - }, - { - "domain_name": "برق و انرژی‌های نو", - "id": 15 - }, - { - "domain_name": "بیمـه‌", - "id": 16 - }, - { - "domain_name": "خانواده", - "id": 27 - }, - { - "domain_name": "انتخابات", - "id": 11 - }, - { - "domain_name": "نفت و گاز", - "id": 50 - }, - { - "domain_name": "تأمین اجتماعی", - "id": 18 - }, - { - "domain_name": "نظام‌های صنفی و حرفه‌ای", - "id": 48 - }, - { - "domain_name": "تعـاون", - "id": 22 - }, - { - "domain_name": "ورزش", - "id": 51 - }, - { - "domain_name": "تقسیمات کشوری و مدیریت محلی", - "id": 24 - }, - { - "domain_name": "آموزش و پرورش", - "id": 3 - }, - { - "domain_name": "ثبت اسناد و املاک", - "id": 25 - }, - { - "domain_name": "سلامت", - "id": 29 - } - ], - "D50_v1": [ - { - "id": 1, - "domain_name": "آب" - }, - { - "id": 2, - "domain_name": "آمار، برنامه و بودجه" - }, - { - "id": 3, - "domain_name": "آموزش و پرورش" - }, - { - "id": 4, - "domain_name": "آموزش عالی، پژوهش و فناوری" - }, - { - "id": 5, - "domain_name": "آیین دادرسی مدنی" - }, - { - "id": 6, - "domain_name": "آیین دادرسی اداری" - }, - { - "id": 7, - "domain_name": "آیین دادرسی کیفری" - }, - { - "id": 8, - "domain_name": "اداری و استخدامی" - }, - { - "id": 9, - "domain_name": "اموال و معاملات دولتی" - }, - { - "id": 10, - "domain_name": "اطلاعات، امنیت و نظامی ،انتظامی" - }, - { - "id": 11, - "domain_name": "امور زیربنایی" - }, - { - "id": 12, - "domain_name": "انتخابات" - }, - { - "id": 13, - "domain_name": "اوقاف، اماکن دینی و امور مذهبی" - }, - { - "id": 14, - "domain_name": "ایثـارگران" - }, - { - "id": 15, - "domain_name": "بانکداری" - }, - { - "id": 16, - "domain_name": "برق و انرژی های نوین" - }, - { - "id": 17, - "domain_name": "بیمـه" - }, - { - "id": 18, - "domain_name": "پولی و مالی" - }, - { - "id": 19, - "domain_name": "تأمین اجتماعی" - }, - { - "id": 20, - "domain_name": "تجارت" - }, - { - "id": 21, - "domain_name": "تشکلهای مدنی و احزاب" - }, - { - "id": 22, - "domain_name": "تشکیلات و امور اداری قوه قضائیه" - }, - { - "id": 23, - "domain_name": "تعـاون" - }, - { - "id": 24, - "domain_name": "تعزیرات حکومتی" - }, - { - "id": 25, - "domain_name": "تقسیمات کشوری و مدیریت محلی" - }, - { - "id": 26, - "domain_name": "ثبت اسناد و املاک" - }, - { - "id": 27, - "domain_name": "حمل و نقل" - }, - { - "id": 28, - "domain_name": "خانواده" - }, - { - "id": 29, - "domain_name": "رسانه" - }, - { - "id": 30, - "domain_name": "سلامت" - }, - { - "id": 31, - "domain_name": "صنعـت" - }, - { - "id": 32, - "domain_name": "ارتباطات و فناوری اطلاعات" - }, - { - "id": 33, - "domain_name": "فرهنگ و هنر" - }, - { - "id": 34, - "domain_name": "کار" - }, - { - "id": 35, - "domain_name": "کشاورزی و دامپروری" - }, - { - "id": 36, - "domain_name": "کیفـری" - }, - { - "id": 37, - "domain_name": "مالکیت فکری" - }, - { - "id": 38, - "domain_name": "مالیات" - }, - { - "id": 39, - "domain_name": "محاسبات عمومی" - }, - { - "id": 40, - "domain_name": "محیط زیست" - }, - { - "id": 41, - "domain_name": "مدنی و امور حسبی" - }, - { - "id": 42, - "domain_name": "مسکن و شهرسازی" - }, - { - "id": 43, - "domain_name": "مصرف" - }, - { - "id": 44, - "domain_name": "معـدن" - }, - { - "id": 45, - "domain_name": "مناطق آزاد و ویژه اقتصادی" - }, - { - "id": 46, - "domain_name": "میراث فرهنگی، گردشگری و صنایع دستی" - }, - { - "id": 47, - "domain_name": "نظام قانون‌گذاری" - }, - { - "id": 48, - "domain_name": "نظامهای صنفی و حرفهای" - }, - { - "id": 49, - "domain_name": "نفت و گاز" - }, - { - "id": 50, - "domain_name": "ورزش" - } - ] -} \ No newline at end of file diff --git a/app/temp_codes.py b/app/temp_codes.py index d8cbc5e..eed9af3 100644 --- a/app/temp_codes.py +++ b/app/temp_codes.py @@ -1,17 +1,18 @@ import os from dotenv import load_dotenv from app.common.text_normalizer import TextNormalizer + # from general import * from app.common.general_functions import * from app.common.elastic_helper import ElasticHelper from app.for_ai.create_relation_tags import * from app.temp_refactor_gn_dataset import * -load_dotenv(dotenv_path='config.env') +load_dotenv(dotenv_path="config.env") -host=os.getenv('HOST_160') -password=os.getenv('HOST_160_PASS') +host = os.getenv("HOST_160") +password = os.getenv("HOST_160_PASS") # host=os.getenv('HOST_112') # password=os.getenv('HOST_112_PASS') @@ -54,8 +55,8 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map) # elastic.restorFileToElastic2('G:/Project2/111/server112/mj_qa_section-m1.zip', 'mj_qa_section-m1', 'majles', False, 'mj_qa_section') # elastic.backupIndexToZipfile("G:/Project2/111", "gn_calendar") -#elastic.createIndex( 'gn_calendar', 'general', 'gn_calendar') -#elastic.restorFileToElastic2('G:/Project2/111/gn_calendar.zip', 'gn_calendar', 'general', False, 'gn_calendar') +# elastic.createIndex( 'gn_calendar', 'general', 'gn_calendar') +# elastic.restorFileToElastic2('G:/Project2/111/gn_calendar.zip', 'gn_calendar', 'general', False, 'gn_calendar') # elastic.createIndex( 'gn_synonym', 'general', 'gn_synonym') # elastic.restorFileToElastic2('G:/Project2/111/server112/gn_synonym.zip', 'gn_synonym', 'general', False, 'gn_synonym') @@ -65,22 +66,22 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map) # elastic.restorFileToElastic2('G:/Project2/111/mn_sanad.zip', 'mn_sanad', 'monir', False, 'mn_sanad') -#elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section") -#elastic.restorFileToElastic2('G:/Project2/111/mj_qa_section.zip', 'mj_qa_section', 'majles', False, 'mj_qa_section') -#elastic.restorFileToElastic2('G:/Project2/111/gn_setting.zip', 'gn_setting', 'general', False, 'gn_setting') -#------------------------------------------------------- +# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section") +# elastic.restorFileToElastic2('G:/Project2/111/mj_qa_section.zip', 'mj_qa_section', 'majles', False, 'mj_qa_section') +# elastic.restorFileToElastic2('G:/Project2/111/gn_setting.zip', 'gn_setting', 'general', False, 'gn_setting') +# ------------------------------------------------------- ## # elastic.backupIndexToZipfile("G:/Project2/111", "dh_haditha") # elastic.backupIndexToZipfile("G:/Project2/111", "dh_parag_bge") # elastic.backupIndexToZipfile("G:/Project2/111", "gn_dataset") -#elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section") -#elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section_ai") +# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section") +# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section_ai") # elastic.backupIndexToZipfile("G:/Project2/111", "mn_crition") -#moveDataset1(elastic, "G:/Project2/111/gn_dataset_14031125.zip", "gn_dataset2") +# moveDataset1(elastic, "G:/Project2/111/gn_dataset_14031125.zip", "gn_dataset2") -#------------------------------------------------------- +# ------------------------------------------------------- ## backup from hamfahmi.ir -#------------------------------------------------------- +# ------------------------------------------------------- # elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_bayanat") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_synonym") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_log_search") @@ -98,14 +99,13 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map) # elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_steps") # ??? # elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_nesha") -#------------------------------------------------------- +# ------------------------------------------------------- - -#------------------------------------------------------- +# ------------------------------------------------------- ## backup from 160 -#------------------------------------------------------- -path_back = 'G:/Project2/111/server112/' +# ------------------------------------------------------- +path_back = "G:/Project2/111/server112/" # elastic.backupIndexToZipfile(path_back, "gn_log_change") # elastic.backupIndexToZipfile(path_back, "gn_log_action") # elastic.backupIndexToZipfile(path_back, "gn_log_search") @@ -124,7 +124,7 @@ path_back = 'G:/Project2/111/server112/' # elastic.backupIndexToZipfile(path_back, "mj_rg_section") # elastic.backupIndexToZipfile(path_back, "mj_qa_qanon") ############elastic.backupIndexToZipfile(path_back, "rrk_index") -#elastic.backupIndexToZipfile(path_back, "mj_df_qanon") +# elastic.backupIndexToZipfile(path_back, "mj_df_qanon") ######elastic.backupIndexToZipfile(path_back, "mj_qa_qanon_ai") # elastic.backupIndexToZipfile(path_back, "mj_qa_section_ai") @@ -136,9 +136,9 @@ path_back = 'G:/Project2/111/server112/' # gn_dataset2 # gn_setting2 -#------------------------------------------------------- +# ------------------------------------------------------- -#------------------------------------------------------- +# ------------------------------------------------------- ## # ## کد نمونه بازیابی از فایل @@ -146,15 +146,15 @@ path_back = 'G:/Project2/111/server112/' # elastic.createIndex('mj_qa_section', 'majles', 'mj_qa_section') # elastic.zipFileToElastic(path_back, 'mj_qa_section') -#selastic.backupIndexToZipfile("G:/Project2/111", "dh_haditha") +# selastic.backupIndexToZipfile("G:/Project2/111", "dh_haditha") # elastic.backupIndexToZipfile("G:/Project2/111", "gn_calendar") -#elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section") +# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section") # elastic.backupIndexToZipfile("G:/Project2/111", "dh_haditha") -#elastic.backupIndexToZipfile("G:/Project2/111", "dh_volume_temp") -#elastic.restorFileToElastic("G:/Project2/111", "mj_qa_section_ai", 'majles', True, "mj_qa_section") +# elastic.backupIndexToZipfile("G:/Project2/111", "dh_volume_temp") +# elastic.restorFileToElastic("G:/Project2/111", "mj_qa_section_ai", 'majles', True, "mj_qa_section") -#elastic.restorFileToElastic('G:/Project2/111', 'mj_model', 'majles', True, 'mj_model' ) +# elastic.restorFileToElastic('G:/Project2/111', 'mj_model', 'majles', True, 'mj_model' ) # elastic.restorFileToElastic2('G:/Project2/111/mj_model_20250512-003003.zip', 'mj_model', 'majles', True, 'mj_model') # elastic.restorFileToElastic2('G:/Project2/111/mj_qa_section_2_majles_repair.zip', 'mj_qa_section', 'majles', False, 'mj_qa_section') @@ -189,21 +189,21 @@ path_back = 'G:/Project2/111/server112/' # ] # } -#elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section", "mj_qa_section_Aab", body, False, ["content", "simplifies", "tcode_sub_old", "tcode_main_old", "code-ai", "ai_keywords"]) +# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section", "mj_qa_section_Aab", body, False, ["content", "simplifies", "tcode_sub_old", "tcode_main_old", "code-ai", "ai_keywords"]) -#------------------------------------------------------- +# ------------------------------------------------------- #### فایده ای نداشت ....!!! ## مسیر درختی مفید تولید نشد و عنوان قانون هم که فیلد مجزا داریم ! # create_context_ai(elastic, "mj_qa_section" ) -#------------------------------------------------------- +# ------------------------------------------------------- ## -#ai_url_chunk = os.getenv("ai_url_chunk") -#fill_chunk_tags(elastic, ai_url_chunk, "mj_qa_section") +# ai_url_chunk = os.getenv("ai_url_chunk") +# fill_chunk_tags(elastic, ai_url_chunk, "mj_qa_section") -#------------------------------------------------------- +# ------------------------------------------------------- ## # برچسبهای هوشمند @@ -225,23 +225,23 @@ path_back = 'G:/Project2/111/server112/' # resp = json.loads(response.text) # print(resp['result']) -#------------------------------------------------------- +# ------------------------------------------------------- ## ## پشتیبان گیری # path_back = os.getcwd() + '/data_back' -path_back = 'G:/Project2/111' -# if not os.path.exists(path_back) : +path_back = "G:/Project2/111" +# if not os.path.exists(path_back) : # os.makedirs(path_back) # print('---> path_back = ' + path_back) -#elastic.backupIndexToZipfile(path_back, "mj_qa_qanon") +# elastic.backupIndexToZipfile(path_back, "mj_qa_qanon") # elastic.backupIndexToZipfile(path_back, "mj_qa_section") # elastic.backupIndexToZipfile(path_back, "mj_qa_section", '', {}, True, [], ["pos_tags", "chunk_tags", "version_info"]) -#elastic.backupIndexToZipfile(path_back, "mj_qa_section_ai") -#elastic.backupIndexToZipfile(path_back, "mj_rg_section") -#elastic.backupIndexToZipfile(path_back, "mj_qa_opinion") +# elastic.backupIndexToZipfile(path_back, "mj_qa_section_ai") +# elastic.backupIndexToZipfile(path_back, "mj_rg_section") +# elastic.backupIndexToZipfile(path_back, "mj_qa_opinion") ## کد نمونه بازیابی از فایل # path_back = 'G:/Project2/_back/back_data/data_majles/elastic/v1.0/full' @@ -250,68 +250,51 @@ path_back = 'G:/Project2/111' # elastic.restorFileToElastic(path_back, 'gn_log_action') -#------------------------------------------------------- +# ------------------------------------------------------- ## -#------------------------------------------------------- +# ------------------------------------------------------- ## -#------------------------------------------------------- +# ------------------------------------------------------- # -- جهت استخراج دیتاست بخشی از الاستیک برای استفاده در هوش مصنوعی -body= { +body = { "query": { "bool": { - "must": [ - { - "bool": { - "must_not": [ - { - "terms": { - "nlp_tags": [ - "concept_no" - ] - } - }, - { - "exists": { - "field": "ai_keywords" - } - } + "must": [ + { + "bool": { + "must_not": [ + {"terms": {"nlp_tags": ["concept_no"]}}, + {"exists": {"field": "ai_keywords"}}, + ] + } + }, + { + "bool": { + "filter": { + "bool": { + "must": [ + {"terms": {"qanon_etebar": ["", "معتبر"]}}, + { + "terms": { + "title_type": [ + "عادی", + "اصلی", + "موافقتنامه", + "بودجه", + ] + } + }, + ] + } + } + } + }, ] - } - }, - { - "bool": { - "filter": { - "bool": { - "must": [ - { - "terms": { - "qanon_etebar": [ - "", - "معتبر" - ] - } - }, - { - "terms": { - "title_type": [ - "عادی", - "اصلی", - "موافقتنامه", - "بودجه" - ] - } - } - ] - } - } - } } - ] } - } } # elastic.exportToJsonForAI("./data/", "mj_qa_section", "keywords_extract_40K", body, ["content"]) @@ -324,7 +307,7 @@ body= { # } # } # } -#elastic.exportToJsonForAI("./data/", "mj_qa_qanon", "qanon_title", body, ["title", "ts_date", "ts_year"]) +# elastic.exportToJsonForAI("./data/", "mj_qa_qanon", "qanon_title", body, ["title", "ts_date", "ts_year"]) # body={ # "query": { @@ -335,9 +318,9 @@ body= { # } # } # } -#elastic.exportToJsonForAI("./data/", "mj_qa_qanon", "regular_title", body, ["title", "ts_date", "ts_year"]) +# elastic.exportToJsonForAI("./data/", "mj_qa_qanon", "regular_title", body, ["title", "ts_date", "ts_year"]) -#------------------------------------------------------- +# ------------------------------------------------------- -print("finished") \ No newline at end of file +print("finished")