procces refactor majles
This commit is contained in:
+183
-19
@@ -71,8 +71,21 @@ def get_section_title_sample(text):
|
||||
text = re.sub(r"( |\u200C|\>|\<|-|ـ)+", "", text)
|
||||
return text
|
||||
|
||||
def searchSectionId(elastic, index_name, qanon_id, section_title):
|
||||
def searchSectionIdContent(elastic, index_name, qanon_id, section_title, content):
|
||||
score = 100
|
||||
should = []
|
||||
should.append( {
|
||||
"match": {
|
||||
"other_info.full_path": section_title
|
||||
}
|
||||
})
|
||||
|
||||
should.append( {
|
||||
"match": {
|
||||
"content": content
|
||||
}
|
||||
})
|
||||
|
||||
body = {
|
||||
"query": {
|
||||
"bool": {
|
||||
@@ -86,8 +99,61 @@ def searchSectionId(elastic, index_name, qanon_id, section_title):
|
||||
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"other_info.full_path": section_title
|
||||
"bool" : {
|
||||
"should" : should
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s_res = elastic.es.search(index=index_name, body=body)
|
||||
content = get_section_title_sample(content)
|
||||
for item in s_res["hits"]["hits"]:
|
||||
content = item['_source']['content']
|
||||
|
||||
# حذف اضافات
|
||||
content_sample = get_section_title_sample(content)
|
||||
|
||||
if content == content :
|
||||
return item["_id"], 100, item
|
||||
|
||||
return 0, 0, {}
|
||||
|
||||
|
||||
def searchSectionId(elastic, index_name, qanon_id, section_title, other_title=[]):
|
||||
score = 100
|
||||
should = []
|
||||
should.append( {
|
||||
"match": {
|
||||
"other_info.full_path": section_title
|
||||
}
|
||||
})
|
||||
|
||||
for title in other_title :
|
||||
if title and title != section_title :
|
||||
should.append( {
|
||||
"match": {
|
||||
"other_info.full_path": title
|
||||
}
|
||||
})
|
||||
|
||||
body = {
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"term": {
|
||||
"qanon_id": {
|
||||
"value": qanon_id
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
"bool" : {
|
||||
"should" : should
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -100,10 +166,29 @@ def searchSectionId(elastic, index_name, qanon_id, section_title):
|
||||
other_info = item['_source']['other_info']
|
||||
title = other_info['full_path']
|
||||
# حذف اضافات
|
||||
title = get_section_title_sample(title)
|
||||
title_sample = get_section_title_sample(title)
|
||||
|
||||
if title == section_title :
|
||||
if title_sample == section_title :
|
||||
return item["_id"], 100, item
|
||||
|
||||
title_sample2 = title
|
||||
title_sample2 = re.sub(r'^(فصل|کتاب|قسمت|بخش)\s*?(اول|دوم|سوم|چهارم|پنجم|ششم|هفتم|هشتم|نهم|دهم|یازدهم|دوازدهم|سیزدهم|هفدهم|هجدهم|نوزدهم|بیستم)', '', title_sample2)
|
||||
title_sample2 = title_sample2.replace('ماده واحده', '')
|
||||
title_sample2 = title_sample2.replace('متن', '')
|
||||
title_sample2 = title_sample2.replace('پیوست', '')
|
||||
title_sample2 = title_sample2.replace('ضمیمه', '')
|
||||
title_sample2 = title_sample2.strip(' ><')
|
||||
title_sample2 = title_sample2.lstrip(' ><')
|
||||
title_sample2 = get_section_title_sample(title_sample2)
|
||||
|
||||
# if title_sample2 != title_sample :
|
||||
# print('searchSectionId : ', title_sample, title_sample2)
|
||||
|
||||
if title_sample2 == section_title :
|
||||
return item["_id"], 100, item
|
||||
|
||||
if title_sample2 in other_title or title in other_title :
|
||||
return item["_id"], 95, item
|
||||
|
||||
return 0, 0, {}
|
||||
|
||||
@@ -186,7 +271,7 @@ def searchQanonTitleOfContent(elastic, qanon_title, ts_data="", index_name="mj_q
|
||||
return 0, 0, {}
|
||||
|
||||
|
||||
def searchQanonId(elastic, qanon_title, ts_data="", index_name="mj_qa_qanon"):
|
||||
def searchQanonId(elastic, qanon_title, ts_data="", index_name="mj_qa_qanon", ts_ref=""):
|
||||
score = 100
|
||||
body = {
|
||||
"query": {
|
||||
@@ -226,6 +311,10 @@ def searchQanonId(elastic, qanon_title, ts_data="", index_name="mj_qa_qanon"):
|
||||
total = s_res["hits"]["total"]['value']
|
||||
|
||||
qanon_title_sample = re.sub(r"( |\u200C)+", "", qanon_title)
|
||||
qanon_title_sample2 = re.sub(r"^(.+?)(\(.+\))$", r"\1", qanon_title_sample)
|
||||
qanon_title_sample = get_qanon_title_sample(qanon_title_sample)
|
||||
qanon_title_sample2 = get_qanon_title_sample(qanon_title_sample2)
|
||||
|
||||
list_equal = []
|
||||
for item in s_res["hits"]["hits"]:
|
||||
title = item['_source']['title']
|
||||
@@ -233,14 +322,14 @@ def searchQanonId(elastic, qanon_title, ts_data="", index_name="mj_qa_qanon"):
|
||||
title_sample = get_qanon_title_sample(title)
|
||||
title_sample = re.sub(r"( |\u200C)+", "", title_sample)
|
||||
|
||||
if title_sample == qanon_title_sample :
|
||||
if title_sample == qanon_title_sample or title_sample == qanon_title_sample2:
|
||||
list_equal.append(item)
|
||||
else :
|
||||
qanon_title_sample = get_qanon_title_sample(qanon_title)
|
||||
|
||||
title_sample = get_qanon_title_sample(title)
|
||||
|
||||
if title_sample == qanon_title_sample :
|
||||
if title_sample == qanon_title_sample or title_sample == qanon_title_sample2:
|
||||
list_equal.append(item)
|
||||
|
||||
if len(list_equal) == 1 :
|
||||
@@ -251,7 +340,11 @@ def searchQanonId(elastic, qanon_title, ts_data="", index_name="mj_qa_qanon"):
|
||||
return item["_id"], score, item
|
||||
|
||||
for item in list_equal :
|
||||
if ts_data == item['_source']['ts_date'] :
|
||||
if ts_data and ts_data == item['_source']['ts_date'] :
|
||||
score = 100
|
||||
return item["_id"], score, item
|
||||
|
||||
if ts_ref and ts_ref == item['_source']['ts_ref'] :
|
||||
score = 100
|
||||
return item["_id"], score, item
|
||||
|
||||
@@ -263,17 +356,21 @@ def searchQanonId(elastic, qanon_title, ts_data="", index_name="mj_qa_qanon"):
|
||||
return 0, 0, {}
|
||||
|
||||
|
||||
def get_qanon_date(title):
|
||||
def get_qanon_date(title, byDateCorrection = True):
|
||||
# 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_ex = r"مصوب\s*(\d{1,4}/\s*\d{1,4}/\s*\d{1,4})\s*((مجلس|کمیسیون|کمیسیونهای|هیات|شورای).{1,50})$"
|
||||
regex1 = r"مصوب\s*(\d{1,4}/\s*\d{1,4}/\s*\d{1,4})\s*$"
|
||||
regex2 = r"مصوب\s*(\d{1,4}/\s*\d{1,4}/\s*\d{1,4})\s*((مجلس|کمیسیون|نخست وزیر|کمیسیونهای|هیات|شورای).{1,50})$"
|
||||
regex3 = r"تاریخ تصویب\s*:*\s*(\d{1,4}/\s*\d{1,4}/\s*\d{1,4})\s*مرجع تصویب\s*:*\s*((مجلس|کمیسیون|نخست وزیر|کمیسیونهای|هیات|شورای).{1,50})$"
|
||||
regex4 = r"مرجع تصویب\s*:*\s*((مجلس|کمیسیون|نخست وزیر|کمیسیونهای|هیات|شورای).{1,50})\s*تاریخ تصویب\s*:*\s*(\d{1,4}/\s*\d{1,4}/\s*\d{1,4})\s*$"
|
||||
ts_ref = ''
|
||||
qanon_title = ''
|
||||
ts_date = ''
|
||||
title=title.strip().strip(' #=').strip()
|
||||
title=title.replace("\r", " ").replace("\n", " ").replace(" ", " ").replace(" ", " ")
|
||||
title=title.replace("=", "#")
|
||||
title=title.replace("#مصوب#", "#مصوب ")
|
||||
title=title.replace("#مصوب #", "#مصوب ")
|
||||
|
||||
items = title.split('#')
|
||||
if len(items) == 1:
|
||||
qanon_title = items[0]
|
||||
@@ -294,28 +391,89 @@ def get_qanon_date(title):
|
||||
|
||||
if ts_date == '' :
|
||||
# قانون كار مصوب 26/12/1337
|
||||
match = re.search(regex, qanon_title)
|
||||
match = re.search(regex1, qanon_title)
|
||||
if match :
|
||||
#print(f"Match found: {match.group(1)} at position {match.start()}-{match.end()}")
|
||||
ts_date = match.group(1).strip()
|
||||
qanon_title = qanon_title[0:match.start()]
|
||||
|
||||
if ts_date == '':
|
||||
match = re.search(regex_ex, qanon_title)
|
||||
match = re.search(regex2, 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()]
|
||||
|
||||
if ts_date == '':
|
||||
match = re.search(regex3, 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()]
|
||||
|
||||
if ts_date == '':
|
||||
match = re.search(regex4, qanon_title)
|
||||
if match :
|
||||
#print(f"Match found: {match.group(1)} at position {match.start()}-{match.end()}")
|
||||
ts_ref = match.group(1).strip()
|
||||
ts_date = match.group(3).strip()
|
||||
qanon_title = qanon_title[0:match.start()]
|
||||
|
||||
if byDateCorrection and ts_date == '':
|
||||
title = text_normalizer.date_correction(title)
|
||||
return get_qanon_date(title, False)
|
||||
|
||||
return qanon_title, ts_date, ts_ref
|
||||
|
||||
|
||||
# ماده 1 -> ماده یک
|
||||
# ماده دوم -> ماده دیم
|
||||
# ماده دوم -> ماده دویم
|
||||
def get_section_title2(title):
|
||||
|
||||
regex1 = r"^(جزء|بند|ماده|فصل|مبحث|ردیف|جدول|تبصره|پیوست|قسمت)(\s*)(\d+?)$"
|
||||
title=title.strip()
|
||||
title2 = ''
|
||||
title3 = ''
|
||||
match = re.search(regex1, title)
|
||||
if match :
|
||||
try:
|
||||
number = int(match.group(3).strip())
|
||||
s_number1, s_number2 = number_to_persian(number)
|
||||
if s_number1 :
|
||||
title2 = match.group(1) + match.group(2) + s_number1
|
||||
title3 = match.group(1) + match.group(2) + s_number2
|
||||
except :
|
||||
title2 = ''
|
||||
title3 = ''
|
||||
|
||||
if title2 == '' :
|
||||
title2 = title.replace('دیم', 'دوم')
|
||||
title2 = title.replace('دویم', 'دوم')
|
||||
|
||||
return [title2, title3]
|
||||
|
||||
def number_to_persian(num):
|
||||
ones = ["صفر", "یک", "دو", "سه", "چهار", "پنج", "شش", "هفت", "هشت", "نه"]
|
||||
ones2 = ["صفر", "اول", "دوم", "سوم", "چهارم", "پنجم", "ششم", "هفتم", "هشتم", "نهم"]
|
||||
if 0 <= num < 10:
|
||||
return ones[num], ones2[num]
|
||||
else:
|
||||
return ""
|
||||
|
||||
def get_section_correct(title):
|
||||
title=title.strip().strip(' #=').strip()
|
||||
|
||||
if title == 'کل قانون' or title == 'متن قانون' or title == 'متن' or title == 'تمام قانون' or title == 'کل مصوبه':
|
||||
all_titles = ['تمام ماده ها','همه ماده ها','تمام مواد','همه مواد','کل قانون','متن قانون','متن','تمام قانون','کل مصوبه']
|
||||
if title in all_titles :
|
||||
return ['all']
|
||||
|
||||
if re.match(r'^(.+)\(.*\)$', title) :
|
||||
title_1 = re.sub(r'^(.+)\(.*\)$', r'\1', title)
|
||||
if title_1 in all_titles :
|
||||
return ['all']
|
||||
|
||||
title=title.replace('"', '')
|
||||
title=title.replace('اصلاحی', '')
|
||||
@@ -323,10 +481,13 @@ def get_section_correct(title):
|
||||
|
||||
subs = title.split('،')
|
||||
result = []
|
||||
for item in subs :
|
||||
item=re.sub(r"(جزء|بند|ماده|فصل|مبحث|ردیف|جدول|تبصره|پیوست|قسمت)", r"#\1", item)
|
||||
for item in subs :
|
||||
if not item :
|
||||
continue
|
||||
item=re.sub(r"(جزء|بند|ماده|فصل|مبحث|ردیف|جدول|تبصره|باب|کتاب|پیوست|ضمیمه|قسمت)", r"#\1", item)
|
||||
items = item.split('#')
|
||||
items.reverse()
|
||||
if re.match(r"(فصل|مبحث|ردیف|جدول|باب|کتاب|پیوست|ضمیمه|قسمت)", items[-1]) :
|
||||
items.reverse()
|
||||
item = '> '.join(items).strip(' >').replace(' ', '')
|
||||
item = text_normalizer.word_digit_correction(item)
|
||||
result.append(item)
|
||||
@@ -364,4 +525,7 @@ def get__all_section_qanon(elastic, index_name, qanon_id):
|
||||
# print(qanon_title)
|
||||
# qanon_title="قانون الحاق دو تبصره بعنوان تبصره های 3 و 4 به ماده 9 قانون روابط موجر و مستأجر مصوب 13 /2 /1362"
|
||||
# qanon_title = get_qanon_title_sample(qanon_title)
|
||||
# print(qanon_title)
|
||||
# print(qanon_title)
|
||||
|
||||
# print( get_section_number_correct('ماده 1') )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user