permission entity tree list

This commit is contained in:
hsafaei
2025-04-23 16:42:13 +03:30
parent 302f6b5cd8
commit ad5bcb1c44
9 changed files with 663 additions and 31 deletions
+15 -16
View File
@@ -32,18 +32,17 @@ from s11_Tanghih_plan_move import *
cursor, cnxn = create_cursor() cursor, cnxn = create_cursor()
## ایجاد فهرست موضوعات قانون ## ایجاد فهرست موضوعات قانون
projectid = insertProejct() #projectid = insertProejct()
insertProjectItems(cursor, projectid) #insertProjectItems(cursor, projectid)
# 2 # 2
import_law_section_to_elastic(cursor) #import_law_section_to_elastic(cursor)
import_opinion_to_elastic(cursor)
import_regulation_section_to_elastic(cursor) import_regulation_section_to_elastic(cursor)
import_opinion_to_elastic(cursor)
### از ابتدا تا اینجا حدودا 24 ساعت کشید ### از ابتدا تا اینجا حدودا 24 ساعت کشید
@@ -55,22 +54,22 @@ import_regulation_section_update_ref_state(cursor)
import_law_reg_qanon_to_elastic(cursor) import_law_reg_qanon_to_elastic(cursor)
## تا اینجا رسید و خطا داد # ## تا اینجا رسید و خطا داد
import_relations_qanon_lwreg(cursor) # import_relations_qanon_lwreg(cursor)
## اینجا خطا داد # ## اینجا خطا داد
import_relations_qanon_opinion(cursor) # import_relations_qanon_opinion(cursor)
import_lawreg_lwphase_info(cursor) # import_lawreg_lwphase_info(cursor)
cursor.close() cursor.close()
cnxn.close() cnxn.close()
cursor, cnxn = create_cursor('db4minaei') # cursor, cnxn = create_cursor('db4minaei')
#import_tangih_tree_to_list(cursor) # #####import_tangih_tree_to_list(cursor)
import_tanghih_plan_codes(cursor) # import_tanghih_plan_codes(cursor)
cursor.close() # cursor.close()
cnxn.close() # cnxn.close()
+2 -1
View File
@@ -6,7 +6,8 @@ import pyodbc
# دریافت شود و به جای توکن زیر جایگزین شود # دریافت شود و به جای توکن زیر جایگزین شود
# TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3Mzk3ODc1NTQsImp0aSI6IlpKRnhHUjFPR2p6b2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jI3XHUwNjQ1XHUwNjI3XHUwNjQ2XHUwNjQ3IiwiZW1haWwiOiJkZXZAZ21haWwuY29tIiwidXNlcm5hbWUiOiJkZXYiLCJ1c2VyX2xldmVsIjoyfX0.EXMgeLkudzt9_94SoYQm09ERf6ES2FIleXgMAPXkygk'
ACCEPT = "application/json" ACCEPT = "application/json"
HEADERS = {"Authorization": TOKEN, "Accept": ACCEPT} HEADERS = {"Authorization": TOKEN, "Accept": ACCEPT}
+26
View File
@@ -51,6 +51,14 @@ class ElasticHelper():
self.id = "" self.id = ""
def get_doctument(self, index_name, id):
res = self.es.get(index=index_name, id=id)
return res
def exist_doctument(self, index_name, id):
res = self.es.exists(index=index_name, id=id)
return res
def update_index_doc(self, is_update_state, index_name_o, eid, data): def update_index_doc(self, is_update_state, index_name_o, eid, data):
if is_update_state: if is_update_state:
resp = self.es.update(index=index_name_o, id=eid, doc=data) resp = self.es.update(index=index_name_o, id=eid, doc=data)
@@ -220,6 +228,24 @@ class ElasticHelper():
self.createIndex(index_name, app_key, map_name) self.createIndex(index_name, app_key, map_name)
self.zipFileToElastic(file_path, index_name) self.zipFileToElastic(file_path, index_name)
def restorFileToElastic2(self, path_file, index_name, app_key = '', queryDelete = True, map_name='') :
if not os.path.exists(path_file) :
print(' **** error *** path not exist: ', path_file)
return False
file_path = path_file
if not os.path.exists(file_path ) :
return False
if queryDelete :
# اگر وجود داشته باشد، از کاربر برای حذفش سوال میکند
if self.deleteIndex(index_name) :
self.createIndex(index_name, app_key, map_name)
self.zipFileToElastic(file_path, index_name)
else : # اگر وجود داشته باشد پرش می کند و کاری نمیکند
self.createIndex(index_name, app_key, map_name)
self.zipFileToElastic(file_path, index_name)
def renameElasticIndex(self, index_name_i, index_name_o, app_key = '', map_name='') : def renameElasticIndex(self, index_name_i, index_name_o, app_key = '', map_name='') :
+50
View File
@@ -0,0 +1,50 @@
import os
from dotenv import load_dotenv
from text_normalizer import TextNormalizer
# from general import *
from general_functions import *
from elastic_helper import ElasticHelper
from create_relation_tags import *
from temp_refactor_gn_dataset import *
from temp_LawSection_content import *
# cursor, cnxn = create_cursor()
# import_law_section_to_elastic(cursor)
load_dotenv(dotenv_path='config.env')
host=os.getenv('HOST_160')
password=os.getenv('HOST_160_PASS')
print(host)
# print(password)
path_base_map = "G:/Project2/gateway2_main/repo/_other/"
elastic = ElasticHelper(host, password, "elastic", path_base_map)
def import_prev_qanon_info(elastic, file_excel, index_name_o):
# خواند اکسل file_excel
list = []
for item in list :
# item ....
eid = 0 ### ??
data = {
}
try:
resp = elastic.update_index_doc(True, index_name_o, eid, data)
except Exception as e:
save_error(id, e)
file_excel = ''
import_prev_qanon_info(elastic, file_excel, "mj_qa_section" )
+77
View File
@@ -0,0 +1,77 @@
import os
import re
import random
from dotenv import load_dotenv
from text_normalizer import TextNormalizer
# from general import *
from general_functions import *
from elastic_helper import ElasticHelper
from create_relation_tags import *
from temp_refactor_gn_dataset import *
from temp_LawSection_content import *
# cursor, cnxn = create_cursor()
# import_law_section_to_elastic(cursor)
load_dotenv(dotenv_path='config.env')
host=os.getenv('HOST_160')
password=os.getenv('HOST_160_PASS')
print(host)
# print(password)
path_base_map = "G:/Project2/gateway2_main/repo/_other/"
elastic = ElasticHelper(host, password, "elastic", path_base_map)
def import_synonym_virstaran_min(elastic, file_input, index_name_o):
lines = []
with open(file_input, 'r', encoding='utf-8') as file:
# نوشتن خطا در فایل
lines = file.readlines()
row = 0
for item in lines :
item = item.strip()
if not item :
continue
words = []
for w in item.split(','):
w = re.sub(r"\uFEFF|\u00AD|\u00AC", "\u200C", w)
w = w.strip("\u200C").strip()
words.append(w)
if len(words) == 0 :
continue
row = row + 1
if ( row % 10 ) == 0 :
print( 'row = ', row, '/', len(lines))
#eid = 'syn_vr_' + random.randrange(10000)
eid = 'syn_vr_' + str(10000+row)
data = {
'id' : eid,
"main_type": "synonym",
"ref_key": "virastaran",
'words' : words
}
try:
resp = elastic.update_index_doc(False, index_name_o, eid, data)
except Exception as e:
save_error(id, e)
elastic.createIndex("gn_synonym", '', "gn_synonym" )
file_excel = './data/fa_virastarn_min.txt'
import_synonym_virstaran_min(elastic, file_excel, "gn_synonym" )
File diff suppressed because one or more lines are too long
+369
View File
@@ -0,0 +1,369 @@
import os
from dotenv import load_dotenv
import json
import requests
from config_base import *
import pyodbc
import requests
from bs4 import BeautifulSoup
from html import escape
import json
from decimal import Decimal
import datetime
import time
from config_base import *
from general_functions import *
from text_normalizer import TextNormalizer
from elastic_helper import ElasticHelper
##--------------------------------
# بخاطر خطایی که در تبدیل داده به الاستیک برای مواردی که حرف کشیده به جای خط تیر استفاده شده بود، ایجاد شد
# و این داده به مجلس ارسال شد و کارمندان مجلس هم در داده قانون تغییراتی ایجاد کردند
# لازم شد داده مجلس گرفته شود و اصلاح با احتیاط انجام شود تا تغییرات مجلس نیز حفظ شود
# طبیعتا دیگر نیاز به اجرای این برنامه نخواهد بود
##------------------------------------
# cursor, cnxn = create_cursor()
def extract_all_effecteds(elastic, index_name, body={}):
try:
list = elastic.es_iterate_all_documents(index_name, body)
except Exception as e:
save_error(0, e)
count = 0
text_normal = TextNormalizer()
result = {}
for mentry in list:
entry = mentry["source"]
id = entry.get("id", "")
effects = entry.get("effects", [])
for effect in effects :
to_section_id = effect["to_section_id"]
effect_type = effect["effect_type"]
result[to_section_id] = effect_type
return result
def repair_law_section_text(cursor, elastic, index_name, dict_changed, file_log) :
query = '''
select
s.ID as sectionId
,isnull(s.SECTIONTEXT,'') as sectionText -- متن ماده یا تبصره
from lwSection s
left join lwLaw l on s.F_LWLAWID = l.ID
where l.ISLAW = 1
order by s.F_LWLAWID,textOrder
'''
cursor.execute(query)
text_normal = TextNormalizer()
total_count = 0
bulk_data = []
t1= datetime.datetime.now()
print(t1)
file = open(file_log, 'a+', encoding='utf8')
i = 0
while 1:
# print(i)
i=i+1
row = cursor.fetchone()
if not row:
break
# if i > 1000:
# break
# print(row.sectionId)
try:
soup = BeautifulSoup(row.sectionText, "html.parser")
text = soup.get_text("\n", strip=True)
# text = removeHtmlNoTableTag(row.sectionText) # خطا داره
except Exception as e:
text = row.sectionText
text = text_normal.normalize_qanon(text)
text2 = text_normal.normalize_qanon(text,True)
# در این صورت مشکل خطای حذف خط تیره کشیده در این متن نبوده و نیازه به بروز رسانی متن نیست
if len(text) == len(text2) :
if text != text2 :
print(' ??????????> changed content : ', eid, "\ntext:", text , "\ntext2:", text2)
continue
content_len = text.__len__()
eid='qs'+ str(row.sectionId)
if eid in dict_changed :
print( ' ------------------> chenged effected : ', dict_changed[eid])
file.write(' ------------------> chenged effected : '+ dict_changed[eid] + '\n')
if dict_changed[eid] == 'اصلاحی' or dict_changed[eid] == 'جایگزین':
continue
#word_len = len(split_words(text))
data={
'_id':eid,
'_source' : {
'content': text,
'content_len': content_len,
}
}
item = {}
try:
item = elastic.get_doctument(index_name, eid)
# در اینصورت محتوای ماده توسط مجلس تغییر یافته است
text_m = text_normal.normalize_qanon(item['_source']['content'], True).strip().replace(' ', '')
text_m2 = text_normal.normalize_qanon(text, True).strip().replace(' ', '')
if text_m != text_m2 :
print(' ==========> changed content : ', eid, "\ntext:", text_m , "\ntext:", text_m2)
file.write(' ==========> changed content : '+ eid + '\n')
continue
except Exception as e:
# print(type(e).__name__)
continue
# _source = item['_source']
# if 'ref_state' in _source :
# for ref in _source['ref_state'] :
if len(bulk_data) >= 200:
total_count += len(bulk_data)
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid)
elastic.updateBulkList(bulk_data, index_name)
bulk_data = []
bulk_data.append(data)
if len(bulk_data) > 0:
total_count += len(bulk_data)
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid )
elastic.updateBulkList(bulk_data, index_name)
file.close()
print('end success import_law_section_to_elastic')
t2= datetime.datetime.now()
print(t2-t1)
def repair_law_section_ref_state(cursor, elastic, index_name, dict_changed, file_log) :
query = '''
SELECT
gl1.ID as id,
gl4.APPROVEDATE as effect_Date,
gl3.[SECTIONTEXT] as effect_text,
gl3.FULLPATH as effect_section_title,
ls2.SECTIONTEXT as effect_prev_text,
gl4.CAPTION as effect_qanon,
gl1.F_LWLAWID_EFFECTIVE as effect_qanon_id,
gl1.[F_LWSECTIONID_EFFECTIVE] as effect_section_id,
gl1.[F_LWSECTIONID_EFFECTED] as sectionId,
gl2.[SECTIONTEXT],
ls1.CAPTION as effect_section_type,
gl1.DESCRIPTION as description,
gl1.ISIMPLICIT -- تاثیر ضمنی
FROM [Qavanin].[dbo].[lwSectionChange] gl1
left join [lwLawSectionStatus] ls1 on ls1.ID=gl1.[F_CMBASETABLEID_SECTIONSTATUS]
left join lwSection gl2 on gl2.ID=gl1.[F_LWSECTIONID_EFFECTED]
left join lwSection gl3 on gl3.ID=gl1.[F_LWSECTIONID_EFFECTIVE]
left join lwLaw gl4 on gl1.F_LWLAWID_EFFECTIVE=gl4.ID
left join lwSectionLog ls2 on ls2.ID=gl1.[F_LWSECTIONLOGID_EFFECTED]
where
gl4.ISLAW = 1
and gl1.[F_LWSECTIONID_EFFECTED] is not null
order by gl1.[F_LWSECTIONID_EFFECTED], gl4.APPROVEDATE
'''
cursor.execute(query)
text_normal = TextNormalizer()
total_count = 0
bulk_data = []
previd = ''
prev_effect_type = ''
prev_efect_section_id = ''
ref_state_array = []
t1= datetime.datetime.now()
print(t1)
file = open(file_log, 'a+', encoding='utf8')
i = 0
while 1:
# print(i)
i=i+1
row = cursor.fetchone()
if not row:
break
# if i > 3:
# break
# print(row.sectionId)
eid='qs'+ str(row.sectionId)
# lawId='qq'+ str(row.lawId)
if previd == '':
previd = eid
if eid in dict_changed :
print( ' ------------------> chenged effected : ', eid, ' : ', dict_changed[eid])
file.write(' ------------------> chenged effected : '+ eid+ ' : ' + dict_changed[eid] + '\n')
if dict_changed[eid] == 'اصلاحی' or dict_changed[eid] == 'جایگزین':
continue
effect_type = ''
if row.effect_section_type == 'معتبر' :
effect_type = ''
elif row.effect_section_type == 'ساختار الحاقي' or row.effect_section_type == 'ساختار الحاقي مكرر' :
effect_type = 'الحاقی'
elif row.effect_section_type == 'اصلاحي' or row.effect_section_type == 'نامه اصلاحي':
effect_type = 'اصلاحی'
elif row.effect_section_type == 'منسوخه' :
effect_type = 'نسخی'
elif row.effect_section_type == 'احياء' or row.effect_section_type == 'تنفيذ' or row.effect_section_type == 'تمديد':
effect_type = 'تمدیدی'
elif row.effect_section_type == 'تفسير' :
effect_type = 'تفسیری'
elif row.effect_section_type == 'ساختار جايگزين' or row.effect_section_type == 'جايگزين شده':
effect_type = 'جایگزین'
elif row.effect_section_type == 'آزمايشي' :
effect_type = ''
elif row.effect_section_type == 'موقت' :
effect_type = ''
elif row.effect_section_type == 'موقوف الاجراء' :
effect_type = ''
elif row.effect_section_type == 'بااجرامنتفي مي شود' :
effect_type = ''
if row.ISIMPLICIT :
effect_type += ' ضمنی'
# if i == 1 : # اولین بار
# prev_effect_type = effect_type
ref_state = {}
if row.effect_qanon_id :
efect_section_id='qs'+ str(row.effect_section_id)
efect_qanon_id= 'qq'+ str(row.effect_qanon_id)
if prev_efect_section_id == '' :
prev_efect_section_id = efect_section_id
ref_state = {
"id" : row.id,
"qanon_id": efect_qanon_id,
"qanon_title" : text_normal.normalize_qanon(row.effect_qanon),
"qanon_date": row.effect_Date,
"section_id": efect_section_id,
"section_title": normalYehKe(row.effect_section_title),
"ref_key": "qavanin",
"effect_type" : effect_type,
"new_text" : text_normal.normalize_qanon(row.effect_text),
"prev_text" : text_normal.normalize_qanon(row.effect_prev_text),
"description" : text_normal.normalize_qanon(row.description)
}
if previd == eid :
# موارد کاملا تکراری افزوده نشود
if efect_section_id != prev_efect_section_id or prev_effect_type != effect_type:
ref_state_array.append(ref_state)
prev_efect_section_id = efect_section_id
prev_effect_type = effect_type
ref_state={}
continue
data={
'_id':previd,
'_source' : {
'ref_state' : ref_state_array
}
}
bulk_data.append(data)
ref_state_array = []
previd = eid
prev_efect_section_id = efect_section_id
prev_effect_type = effect_type
ref_state_array.append(ref_state)
if len(bulk_data) >= 100:
total_count += len(bulk_data)
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid)
elastic.updateBulkList(bulk_data, index_name)
bulk_data = []
if ref_state_array.__len__() > 0 :
data={
'_id':previd,
'_source' : {
'ref_state' : ref_state_array
}
}
bulk_data.append(data)
# print(bulk_data)
if len(bulk_data) > 0:
total_count += len(bulk_data)
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid)
elastic.updateBulkList(bulk_data, index_name)
bulk_data = []
print('end success import_law_section_update_ref_state')
t2= datetime.datetime.now()
print(t2-t1)
load_dotenv(dotenv_path='config.env')
host=os.getenv('HOST_160')
password=os.getenv('HOST_160_PASS')
path_base_map = "G:/Project2/gateway2_main/repo/_other/"
elastic = ElasticHelper(host, password, "elastic", path_base_map)
cursor, cnxn = create_cursor()
body={
"query": {
"exists": {"field": "effects"}
}
}
dict_effected_sections = extract_all_effecteds(elastic, "mj_df_qanon", body)
# print(dict_effected_sections)
# try:
# item = elastic.get_doctument("mj_qa_section", "3223423")
# except Exception as e:
# print(e)
# print(type(e).__name__)
# print(str(e))
#repair_law_section_text(cursor, elastic, "mj_qa_section", dict_effected_sections, "./output/log_r1.txt")
repair_law_section_ref_state(cursor, elastic, "mj_qa_section", dict_effected_sections, "./output/log_r2.txt")
+46 -9
View File
@@ -16,16 +16,16 @@ from temp_LawSection_content 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')
# host=os.getenv('HOST_161') # host=os.getenv('HOST_161')
# password=os.getenv('HOST_161_PASS') # password=os.getenv('HOST_161_PASS')
@@ -40,6 +40,9 @@ print(host)
path_base_map = "G:/Project2/gateway2_main/repo/_other/" path_base_map = "G:/Project2/gateway2_main/repo/_other/"
elastic = ElasticHelper(host, password, "elastic", path_base_map) elastic = ElasticHelper(host, password, "elastic", path_base_map)
#elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section")
#------------------------------------------------------- #-------------------------------------------------------
## ##
# elastic.backupIndexToZipfile("G:/Project2/111", "dh_parag_bge") # elastic.backupIndexToZipfile("G:/Project2/111", "dh_parag_bge")
@@ -51,18 +54,19 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map)
#------------------------------------------------------- #-------------------------------------------------------
## backup from hamfahmi.ir ## backup from hamfahmi.ir
#------------------------------------------------------- #-------------------------------------------------------
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_bayanat") #elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_bayanat")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_synonym")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_log_search") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_log_search")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_log_change") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_log_change")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_calendar") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_calendar")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_entity") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_entity")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_setting") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_setting")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_research") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_research")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "gn_synonym")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_jahat") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_jahat")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_crition") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_crition")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_sanad") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_sanad")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_steps") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_steps")
# elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_nesha") # elastic.backupIndexToZipfile("G:/Project2/111/server3", "mn_nesha")
@@ -71,12 +75,45 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map)
#-------------------------------------------------------
## backup from 160
#-------------------------------------------------------
# path_back = 'G:/Project2/_back/server160/_back_elastic0126/'
# elastic.backupIndexToZipfile(path_back, "gn_log_change")
# elastic.backupIndexToZipfile(path_back, "gn_log_action")
# elastic.backupIndexToZipfile(path_back, "gn_log_search")
# elastic.backupIndexToZipfile(path_back, "gn_dataset")
# elastic.backupIndexToZipfile(path_back, "gn_setting")
# elastic.backupIndexToZipfile(path_back, "gn_bayanat")
# elastic.backupIndexToZipfile(path_back, "gn_entity")
# elastic.backupIndexToZipfile(path_back, "gn_research")
# elastic.backupIndexToZipfile(path_back, "gn_dataset")
# elastic.backupIndexToZipfile(path_back, "mj_mashruh")
# elastic.backupIndexToZipfile(path_back, "qanonindex")
# elastic.backupIndexToZipfile(path_back, "mj_qa_section")
# elastic.backupIndexToZipfile(path_back, "mj_qa_opinion")
# elastic.backupIndexToZipfile(path_back, "mj_rg_section")
# elastic.backupIndexToZipfile(path_back, "mj_qa_qanon")
# elastic.backupIndexToZipfile(path_back, "rrk_index")
# elastic.backupIndexToZipfile(path_back, "mj_df_qanon")
# elastic.backupIndexToZipfile(path_back, "mj_qa_qanon_ai")
# elastic.backupIndexToZipfile(path_back, "mj_qa_section_ai")
# gn_version
# mj_tmp_qanon
# gn_dataset2
# gn_setting2
#-------------------------------------------------------
#------------------------------------------------------- #-------------------------------------------------------
## ##
# ## کد نمونه بازیابی از فایل # ## کد نمونه بازیابی از فایل
#path_back = 'G:/Project2/111/mj_qa_section.zip' path_back = 'G:/Project2/111/mj_qa_section.zip'
# elastic.createIndex('mj_qa_section', 'majles', 'mj_qa_section') elastic.createIndex('mj_qa_section', 'majles', 'mj_qa_section')
# elastic.zipFileToElastic(path_back, 'mj_qa_section') # elastic.zipFileToElastic(path_back, 'mj_qa_section')
#selastic.backupIndexToZipfile("G:/Project2/111", "dh_haditha") #selastic.backupIndexToZipfile("G:/Project2/111", "dh_haditha")
@@ -88,7 +125,7 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map)
#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")
# elastic.restorFileToElastic('G:/Project2/111', 'dh_haditha', 'dhadith', 'dh_haditha' ) # elastic.restorFileToElastic('G:/Project2/111', 'dh_haditha', 'dhadith', 'dh_haditha' )
elastic.restorFileToElastic('G:/Project2/111', 'gn_calendar') elastic.restorFileToElastic2('G:/Project2/111/mj_qa_section_2_majles_repair.zip', 'mj_qa_section', 'majles', False, 'mj_qa_section')
body= { body= {
+77 -5
View File
@@ -21,7 +21,7 @@ class TextNormalizer:
words = re.split(r"[\t\n\r\.\'\"«»\)\(\]\[\{\}\%\#\$\*\<\>\/,;،؛ \-!?:٭؟]+", text) words = re.split(r"[\t\n\r\.\'\"«»\)\(\]\[\{\}\%\#\$\*\<\>\/,;،؛ \-!?:٭؟]+", text)
return words return words
def normalize_qanon(self, text): def normalize_qanon(self, text, error_state=False):
if not text : if not text :
return "" return ""
@@ -34,7 +34,10 @@ class TextNormalizer:
text = text.replace("\r", "\n") text = text.replace("\r", "\n")
# یکسان سازی اختلاف حروف کیبوردهای مختلف - کدهای مختلف ولی نمایش یکسان # یکسان سازی اختلاف حروف کیبوردهای مختلف - کدهای مختلف ولی نمایش یکسان
text = self.replace_alphabets(text) if error_state :
text = self.replace_alphabets_error(text)
else :
text = self.replace_alphabets(text)
# اعداد چسبیده به کلمات را با یک فاصله جدا می کند # اعداد چسبیده به کلمات را با یک فاصله جدا می کند
text = self.word_digit_correction(text) text = self.word_digit_correction(text)
@@ -103,6 +106,71 @@ class TextNormalizer:
return text return text
def replace_alphabets_error(self, text):
if not text :
return ""
text = re.sub(r"\u200e|\u200f", " ", text) # LTR, RTL
text = re.sub(r"\u00AD|\u00AC", "\u200C", text) # نیم اسپیس خاص
text = re.sub(r"(\u002C)+", "\u200C", text) # نیم اسپیس تکراری
text = re.sub(r"ﺁ|آ", "آ", text)
text = re.sub(r"ﺎ|ٱ|ﺍ", "ا", text)
text = re.sub(r"ٲ|أ|ﺄ|ﺃ", "أ", text)
text = re.sub(r"ﺈ|ﺇ", "إ", text)
text = re.sub(r"ﺐ|ﺏ|ﺑ|ﺒ", "ب", text)
text = re.sub(r"ﭖ|ﭗ|ﭙ|ﭘ", "پ", text)
text = re.sub(r"ﭡ|ٺ|ٹ|ﭞ|ٿ|ټ|ﺕ|ﺗ|ﺖ|ﺘ", "ت", text)
text = re.sub(r"ﺙ|ﺛ|ﺚ|ﺜ", "ث", text)
text = re.sub(r"ﺝ|ڃ|ﺠ|ﺟ", "ج", text)
text = re.sub(r"ڃ|ﭽ|ﭼ", "چ", text)
text = re.sub(r"ﺢ|ﺤ|څ|ځ|ﺣ", "ح", text)
text = re.sub(r"ﺥ|ﺦ|ﺨ|ﺧ", "خ", text)
text = re.sub(r"ڏ|ډ|ﺪ|ﺩ", "د", text)
text = re.sub(r"ﺫ|ﺬ|ذ", "ذ", text)
text = re.sub(r"ڙ|ڗ|ڒ|ڑ|ڕ|ﺭ|ﺮ", "ر", text)
text = re.sub(r"ﺰ|ﺯ", "ز", text)
text = re.sub(r"ﮊ", "ژ", text)
text = re.sub(r"ݭ|ݜ|ﺱ|ﺲ|ښ|ﺴ|ﺳ", "س", text)
text = re.sub(r"ﺵ|ﺶ|ﺸ|ﺷ", "ش", text)
text = re.sub(r"ﺺ|ﺼ|ﺻ|ﺹ", "ص", text)
text = re.sub(r"ﺽ|ﺾ|ﺿ|ﻀ", "ض", text)
text = re.sub(r"ﻁ|ﻂ|ﻃ|ﻄ", "ط", text)
text = re.sub(r"ﻆ|ﻇ|ﻈ", "ظ", text)
text = re.sub(r"ڠ|ﻉ|ﻊ|ﻋ|ﻌ", "ع", text)
text = re.sub(r"ﻎ|ۼ|ﻍ|ﻐ|ﻏ", "غ", text)
text = re.sub(r"ﻒ|ﻑ|ﻔ|ﻓ", "ف", text)
text = re.sub(r"ﻕ|ڤ|ﻖ|ﻗ|ﻘ", "ق", text)
text = re.sub(r"ڭ|ﻚ|ﮎ|ﻜ|ﮏ|ګ|ﻛ|ﮑ|ﮐ|ڪ|ك", "ک", text)
text = re.sub(r"ﮚ|ﮒ|ﮓ|ﮕ|ﮔ", "گ", text)
text = re.sub(r"ﻝ|ﻞ|ﻠ|ڵ|ﻟ", "ل", text)
text = re.sub(r"ﻵ|ﻶ|ﻷ|ﻸ|ﻹ|ﻺ|ﻻ|ﻼ", "لا", text)
text = re.sub(r"ﻡ|ﻤ|ﻢ|ﻣ", "م", text)
text = re.sub(r"ڼ|ﻦ|ﻥ|ﻨ|ﻧ", "ن", text)
text = re.sub(r"ވ|ﯙ|ۈ|ۋ|ﺆ|ۊ|ۇ|ۏ|ۅ|ۉ|ﻭ|ﻮ|ؤ", "و", text)
text = re.sub(r"ﻬ|ھ|ﻩ|ﻫ|ﻪ|ە|ہ", "ه", text)
text = re.sub(r"ﭛ|ﻯ|ۍ|ﻰ|ﻱ|ﻲ|ں|ﻳ|ﻴ|ﯼ|ې|ﯽ|ﯾ|ﯿ|ێ|ے|ى|ي", "ی", text)
text = re.sub(r"¬", "‌", text)
text = re.sub(r"•|·|●|·|・|∙|。|ⴰ", ".", text)
text = re.sub(r",|٬|٫|‚|،", "،", text)
text = re.sub(r"ʕ", "؟", text)
text = re.sub(r"”|“", "\"", text)
text = re.sub(r"۰|٠", "0", text)
text = re.sub(r"۱|١", "1", text)
text = re.sub(r"۲|٢", "2", text)
text = re.sub(r"۳|٣", "3", text)
text = re.sub(r"۴|٤", "4", text)
text = re.sub(r"۵", "5", text)
text = re.sub(r"۶|٦", "6", text)
text = re.sub(r"۷|٧", "7", text)
text = re.sub(r"۸|٨", "8", text)
text = re.sub(r"۹|٩", "9", text)
text = re.sub(r"²", "2", text)
text = re.sub(r"|ِ|ُ|َ|ٍ|ٌ|ً|", "", text)
text = re.sub(r"ـ", "", text) # حذف حروف کشیده # این باعث خطای حذف اضافی شد و با خط بعدی جایگزین شد
return text
def replace_alphabets(self, text): def replace_alphabets(self, text):
if not text : if not text :
return "" return ""
@@ -165,10 +233,14 @@ class TextNormalizer:
text = re.sub(r"۹|٩", "9", text) text = re.sub(r"۹|٩", "9", text)
text = re.sub(r"²", "2", text) text = re.sub(r"²", "2", text)
text = re.sub(r"|ِ|ُ|َ|ٍ|ٌ|ً|", "", text) text = re.sub(r"|ِ|ُ|َ|ٍ|ٌ|ً|", "", text)
#text = re.sub(r"ـ", "", text) # حذف حروف کشیده # این باعث خطای حذف اضافی شد و با خط بعدی جایگزین شد
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) # حذف حروف کشیده
return text return text
def date_correction(self, text): def date_correction(self, text):
# فرمت YYYY/MM/DD یا YYYY-MM-DD --> YYYY/MM/DD # فرمت YYYY/MM/DD یا YYYY-MM-DD --> YYYY/MM/DD
text = re.sub(r'(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})', r'\1/\2/\3', text) text = re.sub(r'(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})', r'\1/\2/\3', text)
@@ -240,7 +312,7 @@ class TextNormalizer:
# "trimLine": True # حذف فضای خالی اضافی در ابتدا و انتهای متن # "trimLine": True # حذف فضای خالی اضافی در ابتدا و انتهای متن
# } # }
normalizer = TextNormalizer() # normalizer = TextNormalizer()
# text = """ # text = """
# سلام -- ـ ـ خوبی # سلام -- ـ ـ خوبی
# دادی ییی بی داد # دادی ییی بی داد
@@ -263,7 +335,7 @@ normalizer = TextNormalizer()
# تبصره 4 ـ در مواردي كه وراث سهم خود از اموال موضوع بندهاي (2)، (4) و (5) اين ماده را به اشخاص ثالث يا وراث ديگر انتقال دهند، علاوه بر ماليات بر ارث به شرح اين فصل، مشمول ماليات طبق مقررات فصول مربوط خواهند بود. # تبصره 4 ـ در مواردي كه وراث سهم خود از اموال موضوع بندهاي (2)، (4) و (5) اين ماده را به اشخاص ثالث يا وراث ديگر انتقال دهند، علاوه بر ماليات بر ارث به شرح اين فصل، مشمول ماليات طبق مقررات فصول مربوط خواهند بود.
# تبصره 5 ـ حقوق ناشي از عقود اجاره به شرط تمليك با بانكها و ساير نهادهاي مالي و اعتباري، نسبت به عرصه و اعيان املاك بر اساس ارزش معاملاتي در تاريخ ثبت انتقال به نام وراث محاسبه خواهد شد. # تبصره 5 ـ حقوق ناشي از عقود اجاره به شرط تمليك با بانكها و ساير نهادهاي مالي و اعتباري، نسبت به عرصه و اعيان املاك بر اساس ارزش معاملاتي در تاريخ ثبت انتقال به نام وراث محاسبه خواهد شد.
# """ # """
# text="سلـام" # # text="سلـام"
# text="46- متون زیر به عنوان تبصره‌ های ( 3 ) و ( 4 ) به ماده (-187-) قانون الحاق می ‌شود:" # # text="46- متون زیر به عنوان تبصره‌ های ( 3 ) و ( 4 ) به ماده (-187-) قانون الحاق می ‌شود:"
# normalized_text = normalizer.normalize_qanon(text) # normalized_text = normalizer.normalize_qanon(text)
# print(normalized_text) # print(normalized_text)