349 lines
13 KiB
Python
349 lines
13 KiB
Python
import os
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
import sys
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
|
|
|
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")
|
|
|
|
|
|
# host = os.getenv("HOST_160")
|
|
# password = os.getenv("HOST_160_PASS")
|
|
|
|
# host=os.getenv('HOST_112')
|
|
# password=os.getenv('HOST_112_PASS')
|
|
|
|
# host=os.getenv('HOST_113')
|
|
# password=os.getenv('HOST_113_PASS')
|
|
|
|
# host=os.getenv('HOST_118')
|
|
# password=os.getenv('HOST_118_PASS')
|
|
|
|
# host=os.getenv('HOST_60')
|
|
# password=os.getenv('HOST_60_PASS')
|
|
|
|
# host=os.getenv('HOST_161')
|
|
# password=os.getenv('HOST_161_PASS')
|
|
|
|
# host=os.getenv('HOST_80')
|
|
# password=os.getenv('HOST_80_PASS')
|
|
|
|
host=os.getenv('HOST_133')
|
|
password=os.getenv('HOST_133_PASS')
|
|
|
|
|
|
print(host)
|
|
# print(password)
|
|
|
|
path_base_map = "G:/Project2/gateway_php/repo/_other/"
|
|
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
|
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_qanon", "mj_qa_qanon_112")
|
|
|
|
# elastic.removeCustomFileds("mj_qa_section", ["tcode","nlp_parser","content_normal","tcode_mains","tcode_subs", "ners_v1", "level", "code-ai"])
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section-m1")
|
|
# elastic.createIndex( index_name='mj_qa_section-m1', app_key='majles', map_name='mj_qa_section')
|
|
# elastic.restorFileToElastic2('G:/Project2/111/mj_qa_section-m1.zip', 'mj_qa_section-m1', 'majles', False, 'mj_qa_section')
|
|
# elastic.restorFileToElastic2(path_file='G:/Project2/111/server112/mj_qa_section-m1.zip', index_name='mj_qa_section-m1', app_key='majles', queryDelete=False, map_name='mj_qa_section')
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_plan")
|
|
# elastic.createIndex( 'mj_plan', 'majles', 'mj_plan')
|
|
# elastic.restorFileToElastic2('G:/Project2/111/mj_plan.zip', 'mj_plan', 'majles', False, 'mj_plan')
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_mashruh")
|
|
# elastic.backupIndexToZipfile("G:/Project2/113", "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", "mn_spr_sanad")
|
|
#elastic.createIndex( 'mn_spr_sanad', 'monir', 'mn_spr_sanad')
|
|
# elastic.restorFileToElastic2('G:/Project2/111/mn_spr_sanad.zip', 'mn_spr_sanad', 'monir', False, 'mn_spr_sanad')
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_domain")
|
|
# elastic.createIndex( 'mj_qa_domain', 'majles', 'mj_qa_domain')
|
|
# elastic.restorFileToElastic2('G:/Project2/111/mj_qa_domain.zip', 'mj_qa_domain', 'majles', False, 'mj_qa_domain')
|
|
|
|
|
|
|
|
# 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_synonym', 'general', 'gn_synonym')
|
|
# elastic.restorFileToElastic2('G:/Project2/111/server112/gn_synonym.zip', 'gn_synonym', 'general', False, 'gn_synonym')
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mn_sanad")
|
|
# elastic.createIndex( 'mn_sanad', 'monir', 'mn_sanad')
|
|
# elastic.restorFileToElastic2('G:/Project2/111/mn_sanad.zip', 'mn_sanad', 'monir', False, 'mn_sanad')
|
|
|
|
|
|
# -------------------------------------------------------
|
|
##
|
|
# 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", "mn_crition")
|
|
# moveDataset1(elastic, "G:/Project2/111/gn_dataset_14031125.zip", "gn_dataset2")
|
|
|
|
# elastic.restorFileToElastic2('G:/Project2/111/mn_crition.zip', 'mn_crition', 'monir', False, 'mn_critions')
|
|
|
|
# -------------------------------------------------------
|
|
## 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")
|
|
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_log_change")
|
|
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_calendar") # ???
|
|
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_entity")
|
|
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_setting")
|
|
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_research") # ???
|
|
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_jahat")
|
|
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_crition")
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_sanad") # ???
|
|
# 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/"
|
|
# elastic.backupIndexToZipfile(path_back, "gn_log_change")
|
|
# elastic.backupIndexToZipfile(path_back, "gn_log_action")
|
|
# elastic.backupIndexToZipfile(path_back, "gn_log_search")
|
|
# elastic.backupIndexToZipfile(path_back, "gn_dataset")
|
|
# elastic.backupIndexToZipfile(path_back, "gn_setting")
|
|
# elastic.backupIndexToZipfile(path_back, "gn_bayanat")
|
|
# elastic.backupIndexToZipfile(path_back, "gn_entity")
|
|
# elastic.backupIndexToZipfile(path_back, "gn_research")
|
|
# elastic.backupIndexToZipfile(path_back, "gn_synonym")
|
|
|
|
|
|
# elastic.backupIndexToZipfile(path_back, "mj_mashruh")
|
|
# elastic.backupIndexToZipfile(path_back, "qanonindex")
|
|
# elastic.backupIndexToZipfile(path_back, "mj_qa_section")
|
|
# elastic.backupIndexToZipfile(path_back, "mj_qa_opinion")
|
|
# 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_qa_qanon_ai")
|
|
# elastic.backupIndexToZipfile(path_back, "mj_qa_section_ai")
|
|
|
|
# elastic.backupIndexToZipfile(path_back, "mj_qa_section-m1")
|
|
# elastic.backupIndexToZipfile(path_back, "gn_setting_help")
|
|
|
|
# gn_version
|
|
# mj_tmp_qanon
|
|
# gn_dataset2
|
|
# gn_setting2
|
|
|
|
# -------------------------------------------------------
|
|
|
|
# -------------------------------------------------------
|
|
##
|
|
|
|
# ## کد نمونه بازیابی از فایل
|
|
# path_back = 'G:/Project2/111/mj_qa_section.zip'
|
|
# elastic.createIndex('mj_qa_section', 'majles', 'mj_qa_section')
|
|
# elastic.zipFileToElastic(path_back, 'mj_qa_section')
|
|
|
|
# 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", "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.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')
|
|
|
|
|
|
# body= {
|
|
# "query": {
|
|
# "terms": {
|
|
# "qanon_id": [
|
|
# "qq83354",
|
|
# "qq83382",
|
|
# "qq112748",
|
|
# "qq112296",
|
|
# "qq83435",
|
|
# "qq114127",
|
|
# "qq175888",
|
|
# "qq85335",
|
|
# "qq84208",
|
|
# "qq114652",
|
|
# "qq114640"
|
|
# ]
|
|
# }
|
|
# },
|
|
# "sort": [
|
|
# {
|
|
# "qanon_id": {
|
|
# "order": "asc"
|
|
# },
|
|
# "child_order": {
|
|
# "order": "asc"
|
|
# }
|
|
# }
|
|
# ]
|
|
# }
|
|
|
|
# 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")
|
|
|
|
|
|
# -------------------------------------------------------
|
|
##
|
|
# برچسبهای هوشمند
|
|
|
|
|
|
# payload={
|
|
# "text":"سلام علیکم"
|
|
# }
|
|
# response = requests.request("POST", ai_url_vec, headers=HEADERS, json=payload)
|
|
# print(response.text)
|
|
# print(response)
|
|
|
|
# payload={
|
|
# "text":"طرفین به منظور اتمام مطالعات و احداث نیروگاههای جریانی ارس و تأسیسات مربوطه، منطقه مشترک ساختمانی و مطالعاتی را تعیین و امنیت این منطقه را در طول مدت اجراء و بهرهبرداری تأمین مینمایند. "
|
|
# }
|
|
# response = requests.request("POST", ai_url_class, headers=HEADERS, json=payload)
|
|
# print(response.text)
|
|
# print(response)
|
|
|
|
# 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) :
|
|
# os.makedirs(path_back)
|
|
# print('---> path_back = ' + path_back)
|
|
|
|
# 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")
|
|
|
|
## کد نمونه بازیابی از فایل
|
|
# path_back = 'G:/Project2/_back/back_data/data_majles/elastic/v1.0/full'
|
|
# elastic.restorFileToElastic(path_back, 'mj_qa_section', 'majles')
|
|
|
|
# elastic.restorFileToElastic(path_back, 'gn_log_action')
|
|
|
|
|
|
# -------------------------------------------------------
|
|
##
|
|
|
|
# -------------------------------------------------------
|
|
##
|
|
|
|
|
|
# -------------------------------------------------------
|
|
# -- جهت استخراج دیتاست بخشی از الاستیک برای استفاده در هوش مصنوعی
|
|
body = {
|
|
"query": {
|
|
"bool": {
|
|
"must": [
|
|
{
|
|
"bool": {
|
|
"must_not": [
|
|
{"terms": {"nlp_tags": ["concept_no"]}},
|
|
{"exists": {"field": "ai_keywords"}},
|
|
]
|
|
}
|
|
},
|
|
{
|
|
"bool": {
|
|
"filter": {
|
|
"bool": {
|
|
"must": [
|
|
{"terms": {"qanon_etebar": ["", "معتبر"]}},
|
|
{
|
|
"terms": {
|
|
"title_type": [
|
|
"عادی",
|
|
"اصلی",
|
|
"موافقتنامه",
|
|
"بودجه",
|
|
]
|
|
}
|
|
},
|
|
]
|
|
}
|
|
}
|
|
}
|
|
},
|
|
]
|
|
}
|
|
}
|
|
}
|
|
# elastic.exportToJsonForAI("./data/", "mj_qa_section", "keywords_extract_40K", body, ["content"])
|
|
|
|
# body={
|
|
# "query": {
|
|
# "term": {
|
|
# "main_type": {
|
|
# "value": "قانون"
|
|
# }
|
|
# }
|
|
# }
|
|
# }
|
|
# elastic.exportToJsonForAI("./data/", "mj_qa_qanon", "qanon_title", body, ["title", "ts_date", "ts_year"])
|
|
|
|
# body={
|
|
# "query": {
|
|
# "term": {
|
|
# "main_type": {
|
|
# "value": "مقرره"
|
|
# }
|
|
# }
|
|
# }
|
|
# }
|
|
# elastic.exportToJsonForAI("./data/", "mj_qa_qanon", "regular_title", body, ["title", "ts_date", "ts_year"])
|
|
|
|
|
|
# -------------------------------------------------------
|
|
|
|
print("finished")
|