nlp_tags embedding
This commit is contained in:
+95
-3
@@ -8,7 +8,7 @@ from html import escape
|
||||
from bs4 import BeautifulSoup
|
||||
import json
|
||||
from decimal import Decimal
|
||||
|
||||
import traceback
|
||||
# from lxml import etree
|
||||
import datetime
|
||||
#enumerate(token_list):
|
||||
@@ -80,6 +80,72 @@ def removeHtmlNoTableTag(html):
|
||||
|
||||
return text
|
||||
|
||||
def split_words(text) :
|
||||
if not text :
|
||||
return []
|
||||
words = re.split(r"[\t\n\r\.\"«»\)\(\]\[,;،؛ \-!?:]+", text)
|
||||
return words
|
||||
|
||||
def normalHeadingTitle(text, last_path = '', keyTitles=[]):
|
||||
global _normalizer
|
||||
lines = text.split('\n')
|
||||
|
||||
## [مجمع عمومی] , (فصل هشتیم مالیات مستغلات) , -اجراء ...
|
||||
text = lines[0].strip("-: ()[]")
|
||||
|
||||
## متن > قسمت الف -> قسمت
|
||||
if last_path :
|
||||
last_path = last_path.split()[0]
|
||||
|
||||
if not keyTitles :
|
||||
keyTitles=['کتاب','باب','فصل','بخش' ,'جلد','قسمت','مبحث','فقره','اصل','مقاله','نکته','دسته','جدول','فرم','ضمیمه', 'پیوست', 'کنوانسیون' , 'قرارداد', 'عهدنامه', 'توافقنامه']
|
||||
|
||||
stopWords = ['شماره', 'در', 'درباره', 'الف', 'ب', 'ج', 'د', 'ه', 'و']
|
||||
words = split_words(text)
|
||||
prefix = ''
|
||||
title = ''
|
||||
i = 0
|
||||
for word in words :
|
||||
if title == '' :
|
||||
if i == 0 :
|
||||
if word in keyTitles :
|
||||
prefix += ' ' + word
|
||||
elif last_path in keyTitles :
|
||||
prefix += ' ' + word
|
||||
|
||||
elif prefix and word.isnumeric() :
|
||||
prefix += ' ' + word
|
||||
elif prefix and _normalizer.is_number(word) :
|
||||
prefix += ' ' + word
|
||||
elif prefix and word in stopWords :
|
||||
prefix += ' ' + word
|
||||
else :
|
||||
title += ' ' + word
|
||||
else :
|
||||
title += ' ' + word
|
||||
i +=1
|
||||
|
||||
# کلمات کلیدی فصل باید ابتدای متن شناسایی شده باشند
|
||||
if i > 5 and prefix == '' :
|
||||
title = text
|
||||
break
|
||||
|
||||
#باب ششم
|
||||
#جرائم و مجازات
|
||||
if prefix and len(lines) > 1 and len(lines[1]) < 100 :
|
||||
title = lines[1].strip("-: ()[]")
|
||||
|
||||
content_type = ''
|
||||
if words and words[0] in ['تبصره', 'بند', 'بخش','تذکر', 'ماده'] :
|
||||
content_type = words[0]
|
||||
elif words and words[0] in keyTitles :
|
||||
content_type = words[0]
|
||||
|
||||
title = title.strip().strip("1234567890 ")
|
||||
return prefix.strip(), title, content_type
|
||||
|
||||
|
||||
|
||||
def normalizerData(data):
|
||||
global _normalizer
|
||||
normalTitle, dates = _normalizer.normalize(data, return_dates=True)
|
||||
@@ -816,7 +882,28 @@ def save_error(error_text,filename):
|
||||
# نوشتن خطا در فایل
|
||||
file.write(error_text + '\n' + 50*'*' + '\n')
|
||||
|
||||
|
||||
def save_error(id=0, e=Exception):
|
||||
err_date = datetime.datetime.now()
|
||||
#filename = err_date.replace('/', '') + '_errors.txt'
|
||||
filename = '1_errors.txt'
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
frame = exc_traceback.tb_frame
|
||||
function_array = traceback.extract_tb(exc_traceback)
|
||||
current_function = function_array[len(function_array)-1]
|
||||
error = f'''
|
||||
id : {id}
|
||||
filename : {current_function.filename}
|
||||
function : {current_function.name}
|
||||
err line no : {current_function.lineno}
|
||||
err line : {current_function.line}
|
||||
err message : {e}
|
||||
err date : {err_date}
|
||||
'''
|
||||
print( '*'*60 + error + '*'*60)
|
||||
with open(filename, 'a+', encoding='utf-8') as file:
|
||||
# نوشتن خطا در فایل
|
||||
file.write(error + '\n' + 50*'*' + '\n')
|
||||
return error
|
||||
|
||||
# تابع برای تعیین نوع عنوان قانونی
|
||||
def getTitleType(caption: str) -> str:
|
||||
@@ -878,4 +965,9 @@ def getTitleType(caption: str) -> str:
|
||||
elif "موافقتنامه" in caption or "موافقت نامه" in caption:
|
||||
return "موافقتنامه"
|
||||
else:
|
||||
return "اصلی"
|
||||
return "اصلی"
|
||||
|
||||
|
||||
# prefix, title = normalHeadingTitle("فصل اول - سیاستها و اصول")
|
||||
# print('prefix :', prefix)
|
||||
# print('title :', title)
|
||||
Reference in New Issue
Block a user