embeding
This commit is contained in:
+30
-13
@@ -16,8 +16,9 @@ class TextNormalizer:
|
||||
|
||||
def split_words(self, text) :
|
||||
if not text :
|
||||
return []
|
||||
words = re.split(r"[\t\n\r\.\"«»\)\(\]\[,;،؛ \-!?:]+", text)
|
||||
return []
|
||||
### “”
|
||||
words = re.split(r"[\t\n\r\.\'\"«»\)\(\]\[\{\}\%\#\$\*\<\>\/,;،؛ \-!?:٭؟]+", text)
|
||||
return words
|
||||
|
||||
def normalize_qanon(self, text):
|
||||
@@ -35,13 +36,13 @@ class TextNormalizer:
|
||||
# یکسان سازی اختلاف حروف کیبوردهای مختلف - کدهای مختلف ولی نمایش یکسان
|
||||
text = self.replace_alphabets(text)
|
||||
|
||||
# اعداد چسبیده به کلمات را با یک فاصله جدا می کند
|
||||
text = self.word_digit_correction(text)
|
||||
|
||||
#فاصله های تکراری و خطوط خالی تکراری را یکی می کند
|
||||
text = re.sub(r"( )+", " ", text)
|
||||
text = re.sub(r"(\n)+", "\n", text)
|
||||
|
||||
# اعداد چسبیده به کلمات را با یک فاصله جدا می کند
|
||||
text = self.word_digit_correction(text)
|
||||
|
||||
# نرمال کردن حروف اختلافی عربی و فارسی
|
||||
text = text.replace("ي", "ی")
|
||||
text = text.replace("ك", "ک")
|
||||
@@ -52,8 +53,15 @@ class TextNormalizer:
|
||||
if not text :
|
||||
return ""
|
||||
|
||||
text = text.replace("\u00a0", " ") # No Break space
|
||||
text = re.sub(r"\u200e|\u200f", " ", text) # LTR, RTL
|
||||
|
||||
text = self.word_digit_correction(text)
|
||||
text = re.sub(r"( )+", " ", text)
|
||||
|
||||
text = self.space_correction(text)
|
||||
text = self.heha_correction(text)
|
||||
|
||||
return text
|
||||
|
||||
|
||||
@@ -99,6 +107,9 @@ class TextNormalizer:
|
||||
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)
|
||||
@@ -178,22 +189,28 @@ class TextNormalizer:
|
||||
|
||||
# اعداد چسبیده به کلمات را با یک فاصله جدا می کند
|
||||
def word_digit_correction(self, text):
|
||||
|
||||
text = re.sub(r"(\200C)(\d+)", r" \2", text)
|
||||
text = re.sub(r"(\d+)(\200C)", r"\1 ", text)
|
||||
|
||||
text = re.sub(r"(\200C)([\t\n\r\.\'\"«»\)\(\]\[\{\}\#\$\*\<\>\/,;،؛ \-!?:٭؟])", r" \2", text)
|
||||
text = re.sub(r"([\t\n\r\.\'\"«»\)\(\]\[\{\}\#\$\*\<\>\/,;،؛ \-!?:٭؟])(\200C)", r"\1 ", text)
|
||||
|
||||
# ## شماره22 -> شماره 22 22/ش2
|
||||
# ### no ش/22 شد\22
|
||||
# text = re.sub(r"([^\d \/\\]+?)(\d)", r"\1 \2", text)
|
||||
# text = re.sub(r"(\d+)([^\d \/\\]+?)", r"\1 \2", text)
|
||||
|
||||
# ر54ر44ر135
|
||||
text = re.sub(r"(\d+?)ر(\d+?)ر(\d+?)", r"\1\/\2\/\3", text)
|
||||
text = re.sub(r"(\d+?)ر(\d+?)", r"\1\/\2", text)
|
||||
|
||||
# text = re.sub(r"(\w+)(\d+)", r"\1 \2", text)
|
||||
# text = re.sub(r"(\d+)(\w+)", r"\1 \2", text)
|
||||
|
||||
# words = re.split(r"[\t\n\r\.\"«»\)\(\]\[,;،؛ \-!?:]+", text)
|
||||
text = re.sub(r"([^\d \/\\]+?)(\d)", r"\1 \2", text)
|
||||
text = re.sub(r"(\d+)([^\d \/\\]+?)", r"\1 \2", text)
|
||||
|
||||
|
||||
#ر5ر135
|
||||
# text = re.sub(r"((\d+)ر)+\d", r"\1 \2", text)
|
||||
return text
|
||||
|
||||
|
||||
## رسیدگیها -> رسیدگیها
|
||||
def heha_correction(self, text):
|
||||
text = re.sub(r"(ه)(ها )", r"\1\2", text)
|
||||
text = re.sub(r"(ه)(های )", r"\1\2", text)
|
||||
|
||||
Reference in New Issue
Block a user