Files
init_dataParser/temp_codes.py
T
2025-04-05 15:42:26 +03:30

259 lines
7.4 KiB
Python

import os
from dotenv import load_dotenv
from text_normalizer import TextNormalizer
# from general import *
from general_functions import *
from elastic_helper import ElasticHelper
from create_relation_tags import *
from temp_refactor_gn_dataset import *
from temp_LawSection_content import *
# cursor, cnxn = create_cursor()
# import_law_section_to_elastic(cursor)
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_60')
# password=os.getenv('HOST_60_PASS')
# host=os.getenv('HOST_80')
# password=os.getenv('HOST_80_PASS')
print(host)
# print(password)
path_base_map = "G:/Project2/gateway2_main/repo/_other/"
elastic = ElasticHelper(host, password, "elastic", path_base_map)
#-------------------------------------------------------
##
# elastic.backupIndexToZipfile("G:/Project2/111", "dh_parag_bge")
# elastic.backupIndexToZipfile("G:/Project2/111", "gn_dataset")
# 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")
#-------------------------------------------------------
## backup from hamfahmi.ir
#-------------------------------------------------------
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_bayanat")
# 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", "gn_synonym")
# 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")
#-------------------------------------------------------
#-------------------------------------------------------
##
# ## کد نمونه بازیابی از فایل
#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')
# elastic.backupIndexToZipfile("G:/Project2/111", "gn_log_action")
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section")
#elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section_ai")
#elastic.restorFileToElastic("G:/Project2/111", "mj_qa_section_ai", 'majles', True, "mj_qa_section")
body= {
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match_phrase": {
"title.ph": {
"query": "نسخ ضمنی",
"boost": 10
}
}
},
{
"match_phrase": {
"content.ph": {
"query": "نسخ ضمنی",
"boost": 10
}
}
}
]
}
},
{
"bool": {
"filter": {
"bool": {
"must": [
{
"term": {
"ts_ref.keyword": "اداره کل حقوقی قوه قضاییه"
}
}
]
}
}
}
}
]
}
}
}
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_opinion", "mj_qa_opinion_naskh", body, False, ["content"])
#-------------------------------------------------------
#### فایده ای نداشت ....!!!
## مسیر درختی مفید تولید نشد و عنوان قانون هم که فیلد مجزا داریم !
# 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"])
#-------------------------------------------------------
print("finished")