This commit is contained in:
hsafaei
2025-09-18 15:48:59 +03:30
parent b4d5671809
commit b005ef64ea
4 changed files with 124 additions and 11 deletions
+2 -2
View File
@@ -75,8 +75,7 @@ class TextNormalizer:
text = re.sub(r"(\n)+", "\n", text) text = re.sub(r"(\n)+", "\n", text)
# نرمال کردن حروف اختلافی عربی و فارسی # نرمال کردن حروف اختلافی عربی و فارسی
text = text.replace("ي", "ی") text = self.yeke_normal(text)
text = text.replace("ك", "ک")
return text return text
@@ -279,6 +278,7 @@ class TextNormalizer:
text = re.sub(r'([\u0600-\u06FF])ـ([\u0600-\u06FF])', r'\1\2', text) # حذف حروف کشیده text = re.sub(r'([\u0600-\u06FF])ـ([\u0600-\u06FF])', r'\1\2', text) # حذف حروف کشیده
text = re.sub(r'([\u0600-\u06FF])ـ', r'\1', text) # حذف حروف کشیده text = re.sub(r'([\u0600-\u06FF])ـ', r'\1', text) # حذف حروف کشیده
text = text.strip("\u200C").strip()
return text return text
+2 -9
View File
@@ -157,11 +157,7 @@ def moveClassifierAiCodes(elastic, index_name_o, data):
#---------------------------------------------- #----------------------------------------------
for label_doc in ai_codes: for label_doc in ai_codes:
label = label_doc["label"] label = text_normal.normalize_qanon(label_doc["label"])
label = re.sub(r"\u00AD|\u00AC", "\u200C", label) # نیم اسپیس خاص
label = label.replace(" ", " ")
label = label.replace("ـ", "")
label = label.strip().strip("\u200C")
label_doc["label"] = label label_doc["label"] = label
if label_doc["score"] >= 1 : if label_doc["score"] >= 1 :
label_doc["score"] = label_doc["score"] / 100 label_doc["score"] = label_doc["score"] / 100
@@ -170,10 +166,7 @@ def moveClassifierAiCodes(elastic, index_name_o, data):
ai_code["score"] = ai_code["score"] / 100 ai_code["score"] = ai_code["score"] / 100
label = ai_code["label"] label = ai_code["label"]
label = re.sub(r"\u00AD|\u00AC", "\u200C", label) # نیم اسپیس خاص label = text_normal.normalize_qanon(ai_code["label"])
label = label.replace(" ", " ")
label = label.replace("ـ", "")
label = label.strip().strip("\u200C")
ai_code["label"] = label ai_code["label"] = label
#---------------------------------------------- #----------------------------------------------
+119
View File
@@ -0,0 +1,119 @@
import os
from dotenv import load_dotenv
import json
import requests
import pyodbc
import requests
from bs4 import BeautifulSoup
from html import escape
import json
from decimal import Decimal
import datetime
import time
from app.common.config_base import *
from app.common.general_functions import *
from app.common.text_normalizer import TextNormalizer
from app.common.elastic_helper import ElasticHelper
##--------------------------------
# لازم است این فیلد پرشود تا مجلس بتواند دسترسی تغییر داشته باشد
##------------------------------------
def repair_ai_codes( elastic, index_name_i, index_name_o, file_log) :
body = {}
try:
list = elastic.es_iterate_all_documents(index_name_i, body)
except Exception as e:
save_error(0, e)
text_normal = TextNormalizer()
total_count = 0
bulk_data = []
t1= datetime.datetime.now()
print(t1)
file = open(file_log, 'a+', encoding='utf8')
i = 0
doc_tags=[]
qanon_id=0
prev_qanon_id = 0
for mentry in list:
entry = mentry["source"]
id = entry.get("id", "")
qanon_id = entry.get("qanon_id", "")
other_info = entry.get("other_info", {})
ai_code = entry.get("ai_code", {})
ai_codes = entry.get("ai_codes", [])
#----------------------------------------------
for label_doc in ai_codes:
label = text_normal.normalize_qanon(label_doc["label"])
label_doc["label"] = label
if label_doc["score"] >= 1 :
label_doc["score"] = label_doc["score"] / 100
if ai_code :
if ai_code["score"] >= 1 :
ai_code["score"] = ai_code["score"] / 100
label = ai_code["label"]
label = text_normal.normalize_qanon(ai_code["label"])
ai_code["label"] = label
#----------------------------------------------
body = {}
if other_info.full_path == 'عنوان' or other_info.full_path=='موخره' or other_info.full_path=='امضاء' :
body = {}
else:
if ai_code :
body['ai_code'] = ai_code
if ai_codes :
body['ai_codes'] = ai_codes
if not body :
continue
eid = id
data={
'_id':eid,
'_source' : body
}
bulk_data.append(data)
i=i+1
if len(bulk_data) >= 100:
total_count += len(bulk_data)
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + qanon_id)
elastic.updateBulkList(bulk_data, index_name_o)
bulk_data = []
if len(bulk_data) > 0:
total_count += len(bulk_data)
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + qanon_id )
elastic.updateBulkList(bulk_data, index_name_o)
file.close()
print('end success import_law_section_to_elastic')
t2= datetime.datetime.now()
print(t2-t1)
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)
repair_ai_codes( elastic, "mj_qa_section", "mj_qa_section", "./output/log__ai_r1.txt")
+1
View File
@@ -0,0 +1 @@
G:/Project2/NLP/SqlToElasticMajles/.env/Scripts/python.exe -m app.for_ai.ai_json_move_to_index.py