excel codes tanghih

This commit is contained in:
hsafaei
2025-05-26 09:11:22 +03:30
parent b77a7fe703
commit cbb98723d8
10 changed files with 578 additions and 14 deletions
+70 -10
View File
@@ -21,6 +21,34 @@ class TextNormalizer:
words = re.split(r"[\t\n\r\.\'\"«»\)\(\]\[\{\}\%\#\$\*\<\>\/,;،؛ \-!?:٭؟]+", text)
return words
def normalize_search_qanon(self, text, error_state=False):
if not text :
return ""
text = text.strip()
# اصلاح خطاهای متن در کد خط
text = self.replace_alphabets(text)
# اعداد چسبیده به کلمات را با یک فاصله جدا می کند
# text = self.word_digit_correction(text)
text = text.replace("\u00a0", " ") # No Break space
text = re.sub(r"\u200e|\u200f", " ", text) # LTR, RTL
#فاصله های تکراری و خطوط خالی تکراری را یکی می کند
text = re.sub(r"( )+", " ", text)
text = re.sub(r"(\n)+", "", text)
# نرمال کردن حروف اختلافی عربی و فارسی
text = self.yeke_normal(text)
# text = self.hamzah_normal(text)
# text = self.alaem_normal(text)
return text
def normalize_qanon(self, text, error_state=False):
if not text :
return ""
@@ -68,7 +96,6 @@ class TextNormalizer:
return text
def normalize_text(self, text):
if not text :
return ""
@@ -89,14 +116,11 @@ class TextNormalizer:
text = re.sub(r"(\n)+", "\n", text)
# نرمال کردن حروف اختلافی عربی و فارسی
if self.options.get("charArNormal", True):
text = text.replace("ي", "ی")
text = text.replace("ك", "ک")
text = self.yeke_normal(text)
# پرش از اختلافات همزه‌ا
if self.options.get("hamzehNormal", False):
text = re.sub(r"ئ|ﺋ", "ی", text)
text = re.sub(r"ؤ|ﺅ", "و", text)
text = re.sub(r"ﺔ|ۀ|ة", "ه", text)
text = re.sub(r"إ|أ", "ا", text)
text = self.hamzah_normal(text)
# اصلاح فاصله‌ها در ترکیب کلمات
if self.options.get("spaceCorrection", False):
text = self.space_correction(text)
@@ -105,6 +129,23 @@ class TextNormalizer:
text = text.strip()
return text
def alaem_normal(self, text):
text = re.sub(r"[\t\n\r\.\'\"«»\)\(\]\[\{\}\%\#\$\*\<\>\/,;،؛\-!?:٭؟]+", "", text)
return text
def yeke_normal(self, text):
text = text.replace("ي", "ی")
text = text.replace("ك", "ک")
return text
def hamzah_normal(self, text):
text = re.sub(r"ئ|ﺋ", "ی", text)
text = re.sub(r"ؤ|ﺅ", "و", text)
text = re.sub(r"ﺔ|ۀ|ة", "ه", text)
text = re.sub(r"إ|أ", "ا", text)
return text
def replace_alphabets_error(self, text):
if not text :
@@ -242,11 +283,21 @@ class TextNormalizer:
def date_correction(self, text):
# فرمت YYYY/MM/DD یا YYYY-MM-DD --> YYYY/MM/DD
text = re.sub(r'(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})', r'\1/\2/\3', text)
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"(\d+?) /(\d+?) /(\d+?)", r"\1/\2/\3", text)
# text = re.sub(r"(\d+?) \\(\d+?) \\(\d+?)", r"\1/\2/\3", text)
# # فرمت YYYY/MM/DD یا YYYY-MM-DD --> YYYY/MM/DD
# text = re.sub(r'(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})', r'\1/\2/\3', text)
# فرمت DD/MM/YYYY یا DD-MM-YYYY ---> YYYY/MM/DD
text = re.sub(r'(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})', r'\3/\2/\1', text)
text = re.sub(r'(\d{4})[\/\-](\d{2})[\/\-](\d{2})', r'\3/\2/\1', text)
text = re.sub(r'(\d{1})[\/\-](\d{1})[\/\-](\d{4})', r'0\1/0\2/\3', text)
return text
def space_correction(self, text):
@@ -280,6 +331,8 @@ class TextNormalizer:
# ### no ش/22 شد\22
# text = re.sub(r"([^\d \/\\]+?)(\d)", r"\1 \2", text)
# text = re.sub(r"(\d+)([^\d \/\\]+?)", r"\1 \2", text)
text = re.sub(r"[^\/](\d+)([\u0600-\u06FF\u0750-\u077F]+?)", r"\1 \2", text)
# ر54ر44ر135
text = re.sub(r"(\d+?)ر(\d+?)ر(\d+?)", r"\1\/\2\/\3", text)
@@ -300,6 +353,13 @@ class TextNormalizer:
return text
def pad_left(self, s, length, char=' '):
if len(s) >= length:
return s
else:
return char * (length - len(s)) + s
# # تست برنامه
# options = {