This commit is contained in:
hsafaei
2025-07-23 11:12:24 +03:30
parent 8f63d947f3
commit 5d87fed26e
3 changed files with 132 additions and 3 deletions
+51 -2
View File
@@ -9,7 +9,7 @@ import pandas as pd
from qanon_functions import *
def importBeforeInfosToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_id , file_log, result_path = ""):
def parseBeforeInfos(elastic, file_excel, file_log, result_path = ""):
df = pd.read_excel(file_excel, sheet_name=0, header=None)
count = 0
rows_list = df.to_dict(orient='records')
@@ -28,6 +28,54 @@ def importBeforeInfosToElastic(elastic, file_excel, index_name_o, tcode_label, t
rows_list_new = []
bulk_data = []
total_count=0
try:
for row in rows_list:
row_id = row[column_names[0]]
qanon_title = row[column_names[1]]
ts_date = row[column_names[3]]
qanon_id = 0
count = count + 1
if (count % 10) == 0 :
print("%s, %.2f " % ( '================== ', (count / total) * 100 if total > 0 else 0))
qanon_title = text_normalizer.normalize_search_qanon(qanon_title)
# جداسازی اعداد چسبیده به کلمات قبل یا بعد مثل
# قانون بودجه سال 1369کل کشور
qanon_title = re.sub(r"([^\/])(\d+)([\u0600-\u06FF\u0750-\u077F]+?)", r"\1\2 \3", qanon_title)
score = 100
qanon_id = 0
# ابتدا از قانونهای خاص که شناسه ذخیره شده دارند جستجو کند
if qanon_title in dict_qanon_id :
score = 100
qanon_id = dict_qanon_id[qanon_title]
state = 'قانون-دستی'
# if qanon_id == 0 :
# continue # این قانون در بانک ما وجود ندارد
# اگر پیدا نشد، از الاستیک جستجو کند
else :
qanon_id, score, item = searchQanonId(elastic, "mj_qa_qanon", qanon_title, ts_date)
# اگر قابل اطمینان نبود، خطا ثبت کند
if score < 90 :
dic_error_qanon_title[qanon_title]=count
print('-'*10 , str(count) , ' qanon error', qanon_title )
file.write('---- qanon error ---' + str(count) + ' ----- ' + qanon_title + '\n')
qanon_id = 0
state = 'خطا-قانون'
else:
state = 'قانون-جستجو'
# ذخیره شناسه ها و وضعیت برای اکسل جدید
# row[5]=qanon_id
# row[6]=section_id
# row[7]=state
# rows_list_new.append(row)
load_dotenv(dotenv_path='config.env')
@@ -47,4 +95,5 @@ path_base_map = "G:/Project2/gateway2_main/repo/_other/"
elastic = ElasticHelper(host, password, "elastic", path_base_map)
#importBeforeInfosToElastic(elastic, "./data/tcodes", "./data/tcodes/result")
parseBeforeInfos(elastic, "./data/جداول بانک قوانین_info-شناسه قانون یار.xlsx" , "پیشاقانون1.txt", "./data/result")
#parseBeforeInfos(elastic, "./data/tcodes", "./data/tcodes/result")