nlp_tags embedding
This commit is contained in:
+41
-4
@@ -3,7 +3,7 @@ import copy
|
||||
import os
|
||||
from tokenizer import Tokenizer
|
||||
from data_helper import DataHelper
|
||||
import general_functions as gf
|
||||
# import general_functions as gf
|
||||
import traceback,sys
|
||||
|
||||
class Normalizer():
|
||||
@@ -287,8 +287,25 @@ class Normalizer():
|
||||
out_sentences = out_sentences + ' ' + wrds[i + 2]
|
||||
return out_sentences
|
||||
|
||||
def normalYehKe(self, text):
|
||||
if(text == None) :
|
||||
return ''
|
||||
|
||||
yeAr = r"ﻱ|ې|ێ|ے|ى|ي|ئ"
|
||||
yeFr= r"ی"
|
||||
keAr = r"ڭ|ﻚ|ﮎ|ﻜ|ﮏ|ګ|ﻛ|ﮑ|ﮐ|ڪ|ك"
|
||||
keFr = r"ک"
|
||||
c1 = sub(yeAr, yeFr, text)
|
||||
c2 = sub(keAr, keFr, c1)
|
||||
c2 = c2.replace('\u00A0', '')
|
||||
return c2.strip()
|
||||
|
||||
|
||||
def is_number(self, word):
|
||||
return word in self.date_normalizer.num_dict
|
||||
|
||||
def normalize(self, doc_string, new_line_elimination=False, return_dates = False):
|
||||
normalized_string = gf.normalYehKe(doc_string)
|
||||
normalized_string = normalYehKe(doc_string)
|
||||
normalized_string = self.sub_alphabets(doc_string)
|
||||
#normalized_string = self.data_helper.clean_text(normalized_string, new_line_elimination).strip()
|
||||
|
||||
@@ -684,6 +701,21 @@ class DateNormalizer():
|
||||
recognized_dates.append(item)
|
||||
return normalized_string, dates, recognized_dates
|
||||
|
||||
# این متد یک متن و ایندکس آغاز و پایان یک عبارت درون آن متن را دریافت می کند
|
||||
# و شماره توکن آغازین و توکن پایانی مربوط به عبارت در متن را بر می گرداند
|
||||
def token_state_finder(normalized_section_content, start_index, end_index):
|
||||
before_substring = normalized_section_content[0:start_index-1].strip()
|
||||
pattern_substring = normalized_section_content[start_index-1:end_index+1].strip()
|
||||
before_substring_token_list = before_substring.strip().split()
|
||||
pattern_token_list = pattern_substring.strip().split()
|
||||
start_token_state = len(before_substring_token_list)
|
||||
end_token_state = len(before_substring_token_list) + (len(pattern_token_list)-1)
|
||||
pattern_tokens_state ={
|
||||
"start_token_state": start_token_state,
|
||||
"end_token_state" : end_token_state
|
||||
}
|
||||
return pattern_tokens_state
|
||||
|
||||
# 24 /12 /1401 متد بررسی الگوی تاریخ
|
||||
def separated_date_format_finder(normalized_string):
|
||||
import re
|
||||
@@ -699,7 +731,7 @@ class DateNormalizer():
|
||||
current_date = founded_item.replace(' ', '')
|
||||
date_parts = current_date.split('/')
|
||||
formal_date = "y" + str(date_parts[2]) + "m" + str(date_parts[1]) + "d" + str(date_parts[0])
|
||||
pattern_tokens_state = gf.token_state_finder(normalized_string, start_index, end_index)
|
||||
pattern_tokens_state = token_state_finder(normalized_string, start_index, end_index)
|
||||
recognized_dates.append(
|
||||
{
|
||||
"original_date" : founded_item,
|
||||
@@ -720,6 +752,11 @@ class DateNormalizer():
|
||||
normalized_string_temp = normalized_string_temp + ' ' + token
|
||||
return normalized_string_temp.strip(), recognized_dates
|
||||
|
||||
def save_error(self, error_text,filename):
|
||||
with open(filename, 'a+', encoding='utf-8') as file:
|
||||
# نوشتن خطا در فایل
|
||||
file.write(error_text + '\n' + 50*'*' + '\n')
|
||||
|
||||
def normalize_dates(self, token_list, additional_token_index_array, token_list_len, previous_slice_index_array= []):
|
||||
try:
|
||||
finded = self.find_date_part(token_list)
|
||||
@@ -738,7 +775,7 @@ class DateNormalizer():
|
||||
err line : {current_function.line}
|
||||
err message : {e}
|
||||
'''
|
||||
gf.save_error(error, filename)
|
||||
save_error(error, filename)
|
||||
|
||||
recognized_dates = []
|
||||
if finded != None:
|
||||
|
||||
Reference in New Issue
Block a user