gn_dataset
This commit is contained in:
@@ -85,7 +85,7 @@ path_back = 'G:/Project2/111'
|
|||||||
|
|
||||||
#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")
|
||||||
elastic.backupIndexToZipfile(path_back, "mj_qa_section", '', {}, True, [], ["pos_tags", "chunk_tags", "version_info"])
|
#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_qa_section_ai")
|
||||||
#elastic.backupIndexToZipfile(path_back, "mj_rg_section")
|
#elastic.backupIndexToZipfile(path_back, "mj_rg_section")
|
||||||
#elastic.backupIndexToZipfile(path_back, "mj_qa_opinion")
|
#elastic.backupIndexToZipfile(path_back, "mj_qa_opinion")
|
||||||
|
|||||||
@@ -421,6 +421,43 @@ class ElasticHelper():
|
|||||||
print(" END Of Import to elastic ", index_name ,"\n")
|
print(" END Of Import to elastic ", index_name ,"\n")
|
||||||
|
|
||||||
|
|
||||||
|
def iterateJsonFile(self, file_path, isZip=True, limit_pack = -1):
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
print("file zip:" , file_path , " not exist iterateJsonFile " )
|
||||||
|
return
|
||||||
|
|
||||||
|
if isZip :
|
||||||
|
fileNo = 0
|
||||||
|
with zipfile.ZipFile(file_path, 'r') as zObject:
|
||||||
|
fileNo +=1
|
||||||
|
print("="*10, " zip fileNo: " , fileNo ," iterateJsonFile - | File Numbers:" ,len(zObject.namelist()) , "=" * 10)
|
||||||
|
|
||||||
|
packNo = 0
|
||||||
|
self.counter = 0
|
||||||
|
for filename in zObject.namelist():
|
||||||
|
packNo += 1
|
||||||
|
if limit_pack != -1 :
|
||||||
|
if packNo > limit_pack :
|
||||||
|
print('limit_data iterateJsonFile ', limit_pack)
|
||||||
|
break
|
||||||
|
|
||||||
|
print("index iterateJsonFile :", '=>' , filename )
|
||||||
|
with zObject.open(filename) as file:
|
||||||
|
data = json.loads(file.read())
|
||||||
|
# Yield each entry
|
||||||
|
# yield data
|
||||||
|
yield from ({"source": hit["_source"], "id": hit["_id"]} for hit in data)
|
||||||
|
else :
|
||||||
|
with open(filename, 'r', encoding='utf-8') as file:
|
||||||
|
data = json.loads(file.read())
|
||||||
|
# Yield each entry
|
||||||
|
# yield from (hit for hit in data)
|
||||||
|
#return data
|
||||||
|
yield from ({"source": hit["_source"], "id": hit["_id"]} for hit in data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def es_iterate_all_documents(self, index, body="", pagesize=250, scroll_timeout="25m", **kwargs):
|
def es_iterate_all_documents(self, index, body="", pagesize=250, scroll_timeout="25m", **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|||||||
+18
-7
@@ -5,16 +5,17 @@ from text_normalizer import TextNormalizer
|
|||||||
from general_functions import *
|
from general_functions import *
|
||||||
from elastic_helper import ElasticHelper
|
from elastic_helper import ElasticHelper
|
||||||
from create_relation_tags import *
|
from create_relation_tags import *
|
||||||
|
from temp_refactor_gn_dataset import *
|
||||||
|
|
||||||
|
|
||||||
load_dotenv(dotenv_path='config.env')
|
load_dotenv(dotenv_path='config.env')
|
||||||
|
|
||||||
|
|
||||||
host=os.getenv('HOST_160')
|
# host=os.getenv('HOST_160')
|
||||||
password=os.getenv('HOST_160_PASS')
|
# password=os.getenv('HOST_160_PASS')
|
||||||
|
|
||||||
# host=os.getenv('HOST_112')
|
host=os.getenv('HOST_112')
|
||||||
# password=os.getenv('HOST_112_PASS')
|
password=os.getenv('HOST_112_PASS')
|
||||||
|
|
||||||
# host=os.getenv('HOST_60')
|
# host=os.getenv('HOST_60')
|
||||||
# password=os.getenv('HOST_60_PASS')
|
# password=os.getenv('HOST_60_PASS')
|
||||||
@@ -31,6 +32,17 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
|||||||
#-------------------------------------------------------
|
#-------------------------------------------------------
|
||||||
##
|
##
|
||||||
|
|
||||||
|
#elastic.backupIndexToZipfile("G:/Project2/111", "gn_dataset")
|
||||||
|
|
||||||
|
moveDataset1(elastic, "G:/Project2/111/gn_dataset_14031125.zip", "gn_dataset")
|
||||||
|
|
||||||
|
|
||||||
|
## کد نمونه بازیابی از فایل
|
||||||
|
#path_back = 'G:/Project2/111'
|
||||||
|
#elastic.restorFileToElastic(path_back, 'gn_dataset_14031125.zip', 'majles', True, 'mj_qa_section')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section")
|
# 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_ai")
|
||||||
#elastic.restorFileToElastic("G:/Project2/111", "mj_qa_section_ai", 'majles', True, "mj_qa_section")
|
#elastic.restorFileToElastic("G:/Project2/111", "mj_qa_section_ai", 'majles', True, "mj_qa_section")
|
||||||
@@ -47,8 +59,8 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
|||||||
#-------------------------------------------------------
|
#-------------------------------------------------------
|
||||||
##
|
##
|
||||||
|
|
||||||
ai_url_chunk = os.getenv("ai_url_chunk")
|
#ai_url_chunk = os.getenv("ai_url_chunk")
|
||||||
fill_chunk_tags(elastic, ai_url_chunk, "mj_qa_section")
|
#fill_chunk_tags(elastic, ai_url_chunk, "mj_qa_section")
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------
|
#-------------------------------------------------------
|
||||||
@@ -63,7 +75,6 @@ fill_chunk_tags(elastic, ai_url_chunk, "mj_qa_section")
|
|||||||
# print(response.text)
|
# print(response.text)
|
||||||
# print(response)
|
# print(response)
|
||||||
|
|
||||||
|
|
||||||
# payload={
|
# payload={
|
||||||
# "text":"طرفین به منظور اتمام مطالعات و احداث نیروگاههای جریانی ارس و تأسیسات مربوطه، منطقه مشترک ساختمانی و مطالعاتی را تعیین و امنیت این منطقه را در طول مدت اجراء و بهرهبرداری تأمین مینمایند. "
|
# "text":"طرفین به منظور اتمام مطالعات و احداث نیروگاههای جریانی ارس و تأسیسات مربوطه، منطقه مشترک ساختمانی و مطالعاتی را تعیین و امنیت این منطقه را در طول مدت اجراء و بهرهبرداری تأمین مینمایند. "
|
||||||
# }
|
# }
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import os
|
||||||
|
from text_normalizer import TextNormalizer
|
||||||
|
# from general import *
|
||||||
|
from general_functions import *
|
||||||
|
from elastic_helper import ElasticHelper
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def moveDataset1(elastic, file, index_name_o):
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
list = elastic.iterateJsonFile(file)
|
||||||
|
except Exception as e:
|
||||||
|
save_error(0, e)
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
text_normal = TextNormalizer()
|
||||||
|
|
||||||
|
for mentry in list:
|
||||||
|
count += 1
|
||||||
|
#print(mentry)
|
||||||
|
|
||||||
|
entry = mentry["source"]
|
||||||
|
id = entry.get("id", "")
|
||||||
|
domain = entry.get("domain", "")
|
||||||
|
|
||||||
|
if domain == 'تغییرات قانون':
|
||||||
|
continue
|
||||||
|
|
||||||
|
#"value":"استخراج کلیدواژه 11 هزارتایی"
|
||||||
|
|
||||||
|
print(id)
|
||||||
|
#print(entry["content"])
|
||||||
|
|
||||||
|
# data = {}
|
||||||
|
# # data["chunk_keywords"]= chunk_keywords
|
||||||
|
# update = False
|
||||||
|
# eid = id
|
||||||
|
# try:
|
||||||
|
# resp = elastic.update_index_doc(update, index_name_o, eid, data)
|
||||||
|
|
||||||
|
# except Exception as e:
|
||||||
|
# save_error(id, e)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
save_error(id, e)
|
||||||
Reference in New Issue
Block a user