Download normalizer.py from Supernova11c/Supernova-Nepali-Normalizer-V2: direct link, hf CLI and curl.
- Browser
- Download file 948 Bytes
-
https://huggingface.co/Supernova11c/Supernova-Nepali-Normalizer-V2/resolve/main/normalizer.py
- Command line
-
hf download hf://Supernova11c/Supernova-Nepali-Normalizer-V2/normalizer.py
-
curl -L -o normalizer.py https://huggingface.co/Supernova11c/Supernova-Nepali-Normalizer-V2/resolve/main/normalizer.py
948 Bytes
| import unicodedata | |
| import regex as re | |
| class SupernovaNepaliNormalizer: | |
| def __init__(self): | |
| self.zero_width_rules = {'\u200c': '', '\u200d': ''} | |
| self.punctuation_rules = {'—': '-', '–': '-', '“': '"', '”': '"', '‘': "'", '’': "'"} | |
| def normalize(self, text): | |
| if text is None: | |
| return "" | |
| text = str(text) | |
| text = unicodedata.normalize("NFC", text) | |
| for old, new in self.zero_width_rules.items(): | |
| text = text.replace(old, new) | |
| for old, new in self.punctuation_rules.items(): | |
| text = text.replace(old, new) | |
| text = text.replace("\\r\\n", "\\n") | |
| text = text.replace("\\r", "\\n") | |
| text = text.replace("\\t", " ") | |
| text = re.sub(r" {2,}", " ", text) | |
| text = re.sub(r" *\\n *", "\\n", text) | |
| text = re.sub(r"\\n{3,}", "\\n\\n", text) | |
| return unicodedata.normalize("NFC", text).strip() | |