Spaces:
Sleeping
Sleeping
Download normalizer.py from Shrouk04/customer_support_agent2: direct link, hf CLI and curl.
- Browser
- Download file 612 Bytes
-
https://huggingface.co/spaces/Shrouk04/customer_support_agent2/resolve/main/normalizer.py
- Command line
-
hf download hf://spaces/Shrouk04/customer_support_agent2/normalizer.py
-
curl -L -o normalizer.py https://huggingface.co/spaces/Shrouk04/customer_support_agent2/resolve/main/normalizer.py
612 Bytes
| #######3 not ued | |
| import re | |
| from pyarabic import araby | |
| def normalize_text(text): | |
| text = text.strip() | |
| # Detect if Arabic | |
| if re.search(r'[\u0600-\u06FF]', text): | |
| # normalization | |
| text = araby.strip_diacritics(text) | |
| text = re.sub('[إأآا]', 'ا', text) | |
| text = text.replace('ة', 'ه') | |
| text = text.replace('ى', 'ي') | |
| text = re.sub('ـ', '', text) | |
| # Common normalization | |
| text = text.lower() | |
| text = re.sub(r"(.)\1{2,}", r"\1\1", text) | |
| text = re.sub(r'\s+', ' ', text) | |
| return text | |