etebar all qanon
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from elasticsearch8 import Elasticsearch,helpers
|
from elasticsearch import Elasticsearch,helpers
|
||||||
|
|
||||||
class ElasticHelper():
|
class ElasticHelper():
|
||||||
|
|
||||||
|
|||||||
+49
-15
@@ -1,5 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import traceback
|
||||||
|
import json
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from config_base import *
|
from config_base import *
|
||||||
# from general_functions import *
|
# from general_functions import *
|
||||||
@@ -357,33 +359,50 @@ def importCodesToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_i
|
|||||||
|
|
||||||
|
|
||||||
def get_qanon_date(title):
|
def get_qanon_date(title):
|
||||||
regex = r"مصوب(\s*\d{1,4}/\d{1,4}/\d{1,4})\s*$"
|
# regex = r"مصوب(\s*\d{1,4}/\d{1,4}/\d{1,4})\s*$"
|
||||||
regex = r"مصوب\s*(\d{1,4}/\s*\d{1,4}/\s*\d{1,4})\s*$"
|
regex = r"مصوب\s*(\d{1,4}/\s*\d{1,4}/\s*\d{1,4})\s*$"
|
||||||
|
regex_ex = r"مصوب\s*(\d{1,4}/\s*\d{1,4}/\s*\d{1,4})\s*((مجلس|کمیسیون|کمیسیونهای|هیات|شورای).{1,50})$"
|
||||||
ts_ref = ''
|
ts_ref = ''
|
||||||
qanon_title = ''
|
qanon_title = ''
|
||||||
ts_date = ''
|
ts_date = ''
|
||||||
|
title=title.strip().strip(' #=').strip()
|
||||||
|
title=title.replace("=", "#")
|
||||||
|
title=title.replace("#مصوب#", "#مصوب ")
|
||||||
|
title=title.replace("#مصوب #", "#مصوب ")
|
||||||
items = title.split('#')
|
items = title.split('#')
|
||||||
if len(items) == 1:
|
if len(items) == 1:
|
||||||
qanon_title = items[0]
|
qanon_title = items[0]
|
||||||
else:
|
elif items :
|
||||||
last = items[-1].strip()
|
last = items[-1].strip()
|
||||||
if 'مصوب' in last :
|
if last.startswith('مصوب'):
|
||||||
ts_date = last.replace('مصوب').strip()
|
ts_date = last.replace('مصوب', '').strip()
|
||||||
|
qanon_title= ' '.join(items[:-1])
|
||||||
|
# قانون تشكيل#وزارت جهاد سازندگي مصوب 08/09/1362 مجلس شوراي اسلامي
|
||||||
|
elif 'مصوب' in last :
|
||||||
|
qanon_title= ' '.join(items)
|
||||||
elif last :
|
elif last :
|
||||||
ts_ref=last
|
ts_ref=last
|
||||||
|
|
||||||
qanon_title= ' '.join(items[:-1])
|
qanon_title= ' '.join(items[:-1])
|
||||||
print('qanon_title', qanon_title)
|
|
||||||
|
# print('qanon_title', qanon_title)
|
||||||
|
|
||||||
|
|
||||||
if ts_date == '' :
|
if ts_date == '' :
|
||||||
# قانون كار مصوب 26/12/1337
|
# قانون كار مصوب 26/12/1337
|
||||||
match = re.search(regex, qanon_title)
|
match = re.search(regex, qanon_title)
|
||||||
if match :
|
if match :
|
||||||
print(f"Match found: {match.group(1)} at position {match.start()}-{match.end()}")
|
#print(f"Match found: {match.group(1)} at position {match.start()}-{match.end()}")
|
||||||
ts_date = match.group(1).strip()
|
ts_date = match.group(1).strip()
|
||||||
qanon_title = qanon_title[0:match.start()]
|
qanon_title = qanon_title[0:match.start()]
|
||||||
|
|
||||||
|
if ts_date == '':
|
||||||
|
match = re.search(regex_ex, qanon_title)
|
||||||
|
if match :
|
||||||
|
#print(f"Match found: {match.group(1)} at position {match.start()}-{match.end()}")
|
||||||
|
ts_date = match.group(1).strip()
|
||||||
|
ts_ref = match.group(2).strip()
|
||||||
|
qanon_title = qanon_title[0:match.start()]
|
||||||
|
|
||||||
|
|
||||||
return qanon_title, ts_date, ts_ref
|
return qanon_title, ts_date, ts_ref
|
||||||
|
|
||||||
@@ -395,6 +414,7 @@ def importEtebarToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_
|
|||||||
rows_list = df.to_dict(orient='records')
|
rows_list = df.to_dict(orient='records')
|
||||||
|
|
||||||
column_names = df.columns.tolist()
|
column_names = df.columns.tolist()
|
||||||
|
column_count = len(column_names)
|
||||||
# print(column_names)
|
# print(column_names)
|
||||||
|
|
||||||
total = len(df[column_names[0]])
|
total = len(df[column_names[0]])
|
||||||
@@ -419,6 +439,8 @@ def importEtebarToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_
|
|||||||
code_state = ""
|
code_state = ""
|
||||||
if title is None or is_nan_or_none_or_empty(title) or title is None or is_nan_or_none_or_empty(title) :
|
if title is None or is_nan_or_none_or_empty(title) or title is None or is_nan_or_none_or_empty(title) :
|
||||||
title = prevRow[column_names[1]]
|
title = prevRow[column_names[1]]
|
||||||
|
else:
|
||||||
|
prevRow = row
|
||||||
|
|
||||||
|
|
||||||
qanon_id = 0
|
qanon_id = 0
|
||||||
@@ -431,18 +453,18 @@ def importEtebarToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_
|
|||||||
|
|
||||||
|
|
||||||
title = text_normalizer.normalize_search_qanon(title)
|
title = text_normalizer.normalize_search_qanon(title)
|
||||||
|
|
||||||
qanon_title, ts_date, ts_ref = get_qanon_date(title)
|
qanon_title, ts_date, ts_ref = get_qanon_date(title)
|
||||||
|
|
||||||
|
|
||||||
qanon_title = text_normalizer.normalize_search_qanon(qanon_title)
|
qanon_title = text_normalizer.normalize_search_qanon(qanon_title)
|
||||||
|
|
||||||
# جداسازی اعداد چسبیده به کلمات قبل یا بعد مثل
|
# جداسازی اعداد چسبیده به کلمات قبل یا بعد مثل
|
||||||
# قانون بودجه سال 1369کل کشور
|
# قانون بودجه سال 1369کل کشور
|
||||||
qanon_title = re.sub(r"([^\/])(\d+)([\u0600-\u06FF\u0750-\u077F]+?)", r"\1\2 \3", qanon_title)
|
qanon_title = re.sub(r"([^\/])(\d+)([\u0600-\u06FF\u0750-\u077F]+?)", r"\1\2 \3", qanon_title)
|
||||||
|
|
||||||
score = 100
|
# قانون ساختمان شاهراه تهران – كرج
|
||||||
|
qanon_title = qanon_title.replace("–", "-")
|
||||||
|
|
||||||
|
score = 100
|
||||||
# ابتدا از قانونهای خاص که شناسه ذخیره شده دارند جستجو کند
|
# ابتدا از قانونهای خاص که شناسه ذخیره شده دارند جستجو کند
|
||||||
if qanon_title in dict_qanon_id :
|
if qanon_title in dict_qanon_id :
|
||||||
score = 100
|
score = 100
|
||||||
@@ -479,9 +501,10 @@ def importEtebarToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_
|
|||||||
# state = 'صحیح'
|
# state = 'صحیح'
|
||||||
|
|
||||||
# ذخیره شناسه ها و وضعیت برای اکسل جدید
|
# ذخیره شناسه ها و وضعیت برای اکسل جدید
|
||||||
row[5]=qanon_id
|
row[column_count+1]=qanon_id
|
||||||
row[6]=section_id
|
row[column_count+2]=section_id
|
||||||
row[7]=state
|
row[column_count+3]=state
|
||||||
|
row[column_count+4]=qanon_title +'#'+ ts_date +'#'+ ts_ref
|
||||||
rows_list_new.append(row)
|
rows_list_new.append(row)
|
||||||
|
|
||||||
data={}
|
data={}
|
||||||
@@ -529,7 +552,11 @@ def importEtebarToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_
|
|||||||
|
|
||||||
|
|
||||||
# columns=['جزء', 'مصوب', 'قانون', 'اصلی', 'ردیف', 'شناسه قانون', 'شناسه جزء', 'وضعیت پردازش']
|
# columns=['جزء', 'مصوب', 'قانون', 'اصلی', 'ردیف', 'شناسه قانون', 'شناسه جزء', 'وضعیت پردازش']
|
||||||
columns=[0, 1, 2, 3, 4, 5, 6, 7]
|
column_names.append(column_count+1)
|
||||||
|
column_names.append(column_count+2)
|
||||||
|
column_names.append(column_count+3)
|
||||||
|
column_names.append(column_count+4)
|
||||||
|
columns= column_names
|
||||||
new_df = pd.DataFrame(rows_list_new, columns=columns)
|
new_df = pd.DataFrame(rows_list_new, columns=columns)
|
||||||
if result_path == '' :
|
if result_path == '' :
|
||||||
directory_path = os.path.dirname(file_excel)
|
directory_path = os.path.dirname(file_excel)
|
||||||
@@ -543,7 +570,10 @@ def importEtebarToElastic(elastic, file_excel, index_name_o, tcode_label, tcode_
|
|||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
tb = traceback.extract_tb(e.__traceback__)
|
||||||
|
print(tb)
|
||||||
|
line_number = tb[-1].lineno # Get the line number of the last call
|
||||||
|
print(f"Error: {e} on line {line_number}")
|
||||||
file.write('----Exception error ---' + str(count) + ' ***' + str(e) + '\n')
|
file.write('----Exception error ---' + str(count) + ' ***' + str(e) + '\n')
|
||||||
|
|
||||||
file.close()
|
file.close()
|
||||||
@@ -789,6 +819,9 @@ def run_Etebar_directory(elastic, directory, output):
|
|||||||
w1 = text_normalizer.split_words(code_name)[0]
|
w1 = text_normalizer.split_words(code_name)[0]
|
||||||
log_file = output + "/log_r_"+w1+".txt"
|
log_file = output + "/log_r_"+w1+".txt"
|
||||||
file_path = os.path.join(directory, file)
|
file_path = os.path.join(directory, file)
|
||||||
|
if code_name != 'کشاورزی' :
|
||||||
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.makedirs(output, exist_ok=True)
|
os.makedirs(output, exist_ok=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -797,6 +830,7 @@ def run_Etebar_directory(elastic, directory, output):
|
|||||||
code_id = 0
|
code_id = 0
|
||||||
importEtebarToElastic(elastic, file_path, "mj_qa_section", code_name, code_id, log_file)
|
importEtebarToElastic(elastic, file_path, "mj_qa_section", code_name, code_id, log_file)
|
||||||
|
|
||||||
|
|
||||||
# if code_name in dic_code_id :
|
# if code_name in dic_code_id :
|
||||||
# code_id = dic_code_id[code_name]
|
# code_id = dic_code_id[code_name]
|
||||||
# importEtebarToElastic(elastic, file_path, "mj_qa_section", code_name, code_id, log_file)
|
# importEtebarToElastic(elastic, file_path, "mj_qa_section", code_name, code_id, log_file)
|
||||||
|
|||||||
Reference in New Issue
Block a user