168 lines
5.5 KiB
Python
168 lines
5.5 KiB
Python
from general_functions import *
|
|
|
|
# هدف تغییر در قالب شناسه قانون برای سادگی بیشتر بود
|
|
# mj_qa_qavanin_1234 --> qq1234
|
|
def changeIdbyCopyToNewIndex(elastic, index_name_i, index_name_o, is_update_state):
|
|
try:
|
|
body = {}
|
|
try:
|
|
list = elastic.es_iterate_all_documents(index_name_i, body)
|
|
except Exception as e:
|
|
save_error(0, e)
|
|
|
|
count = 0
|
|
novalid = -15000000000
|
|
for mentry in list:
|
|
count += 1
|
|
entry = mentry["source"]
|
|
id = "qs" + str(int(entry.get("ref_id", "")))
|
|
eid = id
|
|
|
|
data = entry
|
|
data["id"] = eid
|
|
data["parent_id"] = str(data["parent_id"]).replace("mj_qa_section_", "qs")
|
|
data["qanon_id"] = str(data["qanon_id"]).replace("mj_qa_qavanin_", "qq")
|
|
if "nlp_parser" in data:
|
|
for i in range(len(data["nlp_parser"])):
|
|
if (
|
|
"law_id" in data["nlp_parser"][i]
|
|
and data["nlp_parser"][i]["law_id"] != 0
|
|
):
|
|
data["nlp_parser"][i]["qanon_id"] = "qq" + str(
|
|
data["nlp_parser"][i]["law_id"]
|
|
)
|
|
|
|
if "ref_state" in data:
|
|
for i in range(len(data["ref_state"])):
|
|
if "section_id" in data["ref_state"][i]:
|
|
data["ref_state"][i]["section_id"] = str(data["ref_state"][i]["section_id"]).replace("mj_qa_section_", "qs")
|
|
if "qanon_id" in data["ref_state"][i]:
|
|
data["ref_state"][i]["qanon_id"] = str(data["ref_state"][i]["qanon_id"]).replace("mj_qa_qavanin_", "qq")
|
|
|
|
try:
|
|
resp = elastic.update_index_doc(
|
|
is_update_state, index_name_o, eid, data
|
|
)
|
|
except Exception as e:
|
|
save_error(id, e)
|
|
|
|
except Exception as e:
|
|
# print(repr(e))
|
|
# exit
|
|
save_error(id, e)
|
|
|
|
|
|
|
|
# فعالیتهای گروه مدل سازی منتقل شود
|
|
def moveEmbedingsToNewIndex(elastic, index_name_i, index_name_o):
|
|
try:
|
|
body = {}
|
|
# body = {"query": {"match": {"qanon_id": "mj_qa_qavanin_303040"}}}
|
|
try:
|
|
list = elastic.es_iterate_all_documents(index_name_i, body)
|
|
except Exception as e:
|
|
save_error(0, e)
|
|
|
|
count = 0
|
|
novalid = -15000000000
|
|
for mentry in list:
|
|
count += 1
|
|
entry = mentry["source"]
|
|
id = "qs" + str(int(entry.get("ref_id", "")))
|
|
eid = id
|
|
|
|
rules = entry.get("embeddings", [])
|
|
data = {"embeddings": rules}
|
|
|
|
try:
|
|
resp = elastic.update_index_doc(True, index_name_o, eid, data)
|
|
except Exception as e:
|
|
save_error(id, e)
|
|
|
|
except Exception as e:
|
|
save_error(id, e)
|
|
|
|
# فعالیتهای گروه مدل سازی منتقل شود
|
|
def moveRulesToNewIndex(elastic, index_name_i, index_name_o):
|
|
try:
|
|
body = {"query": {"bool": {"must": [{"exists": {"field": "rules.state"}}]}}}
|
|
try:
|
|
list = elastic.es_iterate_all_documents(index_name_i, body)
|
|
except Exception as e:
|
|
save_error(0, e)
|
|
|
|
count = 0
|
|
novalid = -15000000000
|
|
for mentry in list:
|
|
count += 1
|
|
entry = mentry["source"]
|
|
id = "qs" + str(int(entry.get("ref_id", "")))
|
|
eid = id
|
|
|
|
rules = entry.get("rules", [])
|
|
data = {"rules": rules}
|
|
|
|
try:
|
|
resp = elastic.update_index_doc(True, index_name_o, eid, data)
|
|
except Exception as e:
|
|
save_error(id, e)
|
|
|
|
except Exception as e:
|
|
save_error(id, e)
|
|
|
|
|
|
def moveCustomFileds(elastic, index_name_i, index_name_o, fields=[], body = {}):
|
|
|
|
try:
|
|
|
|
try:
|
|
list = elastic.es_iterate_all_documents(index_name_i, body)
|
|
except Exception as e:
|
|
save_error(0, e)
|
|
|
|
count = 0
|
|
for mentry in list:
|
|
count += 1
|
|
entry = mentry["source"]
|
|
id = mentry["id"]
|
|
eid = id
|
|
|
|
if (count % 100) == 0 :
|
|
print("%s -> %.2f " % (id , (count / elastic.total) if elastic.total > 0 else 0))
|
|
|
|
data_filled = False
|
|
data = {}
|
|
for col in fields:
|
|
dCol = entry.get(col, None)
|
|
if dCol is None:
|
|
continue
|
|
data[col] = dCol
|
|
data_filled = True
|
|
|
|
if not data_filled :
|
|
continue
|
|
|
|
try:
|
|
resp = elastic.update_index_doc(True, index_name_o, eid, data)
|
|
except Exception as e:
|
|
print(e)
|
|
# save_error(id, e)
|
|
|
|
except Exception as e:
|
|
print("1111")
|
|
print(e)
|
|
|
|
# save_error(id, e)
|
|
|
|
|
|
# elastic = ElasticHelper("http://127.0.0.1:6900", "FuVur05YO60I7YWIP*lc")
|
|
# elastic.checkIndex(index_name_o)
|
|
|
|
#copyToNewIndex(elastic, "mj_qa_section-v05", "mj_qa_section-v01", False)
|
|
#print("**********copyToNewIndex finished**********")
|
|
# moveEmbedingsToNewIndex(elastic, "semantic_search-v06", "mj_qa_section-v02")
|
|
# print("**********moveEmbedings finished**********")
|
|
# moveRulesToNewIndex(elastic, "qanon_section-v02", "mj_qa_section-v02")
|
|
# moveCustomFileds(elastic, "mj_qa_section-v01", "mj_qa_section-v02", ["ners_v1", "nlp_parser", "code-ai"])
|
|
# print("finished")
|