1
This commit is contained in:
+55
-50
@@ -33,7 +33,7 @@ def is_nan_or_none_or_empty(value):
|
||||
return False
|
||||
|
||||
|
||||
def get_qanon_title_sample(text):
|
||||
def get_qanon_title_sample(text, maxState=True):
|
||||
|
||||
spell_list = [
|
||||
"ائیننامه[آئین نامه]=آئین نامه",
|
||||
@@ -45,15 +45,22 @@ def get_qanon_title_sample(text):
|
||||
]
|
||||
|
||||
|
||||
text = re.sub(r"(\d+?)\.(\d+?)\.(\d+?)", r"\1/\2/\3", text)
|
||||
text = text_normalizer.date_correction(text)
|
||||
text = text_normalizer.word_digit_correction(text)
|
||||
text = text_normalizer.hamzah_normal(text)
|
||||
text = text_normalizer.alaem_normal(text)
|
||||
text = re.sub(r"( |\u200C)+", "", text)
|
||||
text = re.sub(r"(\u200C)+", "", text)
|
||||
# بدون : /
|
||||
text = re.sub(r"[\t\n\r\.\'\"«»\)\(\]\[\{\}\%\#\$\*\<\>,;،؛\-!?:٭؟]+", "", text)
|
||||
if maxState :
|
||||
text = text_normalizer.alaem_normal(text)
|
||||
text = re.sub(r"( |\u200C)+", "", text)
|
||||
text = text.replace("اء", "ا")
|
||||
|
||||
if text.startswith('فصل'):
|
||||
# در آدرس دهی چون براساس شماره ماده هست فصل مهم نیست. چون شماره ماده کلی هست
|
||||
text = re.sub(r"^(فصل[^>]>)+", "", text)
|
||||
if text.startswith('فصل'):
|
||||
# در آدرس دهی چون براساس شماره ماده هست فصل مهم نیست. چون شماره ماده کلی هست
|
||||
text = re.sub(r"^(فصل[^>]>)+", "", text)
|
||||
|
||||
return text
|
||||
|
||||
def get_section_title_sample(text):
|
||||
@@ -110,56 +117,45 @@ def get_dict_qanon_title(file_path):
|
||||
return dict
|
||||
|
||||
|
||||
def searchQanonTitleOfContent(elastic, index_name, qanon_title, ts_data=""):
|
||||
def searchQanonTitleOfContent(elastic, qanon_title, ts_data="", index_name="mj_qa_section"):
|
||||
score = 100
|
||||
body = {
|
||||
|
||||
|
||||
body = {
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
{
|
||||
"match": {
|
||||
"title.keyword": {
|
||||
"value": qanon_title
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
s_res = elastic.es.search(index=index_name, body=body)
|
||||
total = s_res["hits"]["total"]['value']
|
||||
if total == 1 :
|
||||
item = s_res["hits"]["hits"][0]
|
||||
return item["_id"], score, item
|
||||
|
||||
if total == 0 :
|
||||
body = {
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [
|
||||
"more_like_this": {
|
||||
"fields": [
|
||||
"content.fa"
|
||||
],
|
||||
"like": qanon_title,
|
||||
"min_term_freq": 1,
|
||||
"max_query_terms": 12
|
||||
{
|
||||
"more_like_this": {
|
||||
"fields": [
|
||||
"content.fa"
|
||||
],
|
||||
"like": qanon_title,
|
||||
"min_term_freq": 1,
|
||||
"max_query_terms": 12
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": {
|
||||
"other_info.full_path": "عنوان"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
s_res = elastic.es.search(index=index_name, body=body)
|
||||
total = s_res["hits"]["total"]['value']
|
||||
|
||||
}
|
||||
|
||||
s_res = elastic.es.search(index=index_name, body=body)
|
||||
total = s_res["hits"]["total"]['value']
|
||||
|
||||
qanon_title_sample = re.sub(r"( |\u200C)+", "", qanon_title)
|
||||
list_equal = []
|
||||
for item in s_res["hits"]["hits"]:
|
||||
title = item['_source']['title']
|
||||
title = item['_source']['content']
|
||||
# حذف اسپیسها
|
||||
title_sample = re.sub(r"( |\u200C)+", "", title)
|
||||
|
||||
|
||||
if title_sample == qanon_title_sample :
|
||||
list_equal.append(item)
|
||||
else :
|
||||
@@ -175,22 +171,22 @@ def searchQanonTitleOfContent(elastic, index_name, qanon_title, ts_data=""):
|
||||
score = 90
|
||||
if ts_data == item['_source']['ts_date'] :
|
||||
score = 100
|
||||
return item["_id"], score, item
|
||||
return item['_source']["qanon_id"], score, item
|
||||
|
||||
for item in list_equal :
|
||||
if ts_data == item['_source']['ts_date'] :
|
||||
score = 100
|
||||
return item["_id"], score, item
|
||||
return item['_source']["qanon_id"], score, item
|
||||
|
||||
if len(list_equal) :
|
||||
score = 90
|
||||
score = 80
|
||||
item = list_equal[0]
|
||||
return item["_id"], score, item
|
||||
return item['_source']["qanon_id"], score, item
|
||||
|
||||
return 0, 0, {}
|
||||
|
||||
|
||||
def searchQanonId(elastic, index_name, qanon_title, ts_data=""):
|
||||
def searchQanonId(elastic, qanon_title, ts_data="", index_name="mj_qa_qanon"):
|
||||
score = 100
|
||||
body = {
|
||||
"query": {
|
||||
@@ -234,8 +230,9 @@ def searchQanonId(elastic, index_name, qanon_title, ts_data=""):
|
||||
for item in s_res["hits"]["hits"]:
|
||||
title = item['_source']['title']
|
||||
# حذف اسپیسها
|
||||
title_sample = re.sub(r"( |\u200C)+", "", title)
|
||||
|
||||
title_sample = get_qanon_title_sample(title)
|
||||
title_sample = re.sub(r"( |\u200C)+", "", title_sample)
|
||||
|
||||
if title_sample == qanon_title_sample :
|
||||
list_equal.append(item)
|
||||
else :
|
||||
@@ -259,7 +256,7 @@ def searchQanonId(elastic, index_name, qanon_title, ts_data=""):
|
||||
return item["_id"], score, item
|
||||
|
||||
if len(list_equal) :
|
||||
score = 90
|
||||
score = 80
|
||||
item = list_equal[0]
|
||||
return item["_id"], score, item
|
||||
|
||||
@@ -360,3 +357,11 @@ def get__all_section_qanon(elastic, index_name, qanon_id):
|
||||
result.append(item["_id"])
|
||||
return result
|
||||
|
||||
|
||||
|
||||
# qanon_title=" قانون الحاق دو تبصره به عنوان تبصره های 3 و 4 به ماده 9 قانون روابط موجر و مستأجر مصوب 1362.2.13"
|
||||
# qanon_title = get_qanon_title_sample(qanon_title)
|
||||
# print(qanon_title)
|
||||
# qanon_title="قانون الحاق دو تبصره بعنوان تبصره های 3 و 4 به ماده 9 قانون روابط موجر و مستأجر مصوب 13 /2 /1362"
|
||||
# qanon_title = get_qanon_title_sample(qanon_title)
|
||||
# print(qanon_title)
|
||||
Reference in New Issue
Block a user