Download demo/src/normalize.py from AriaAICompany/dlp-lab: direct link, hf CLI and curl.
- Browser
- Download file 693 Bytes
-
https://huggingface.co/datasets/AriaAICompany/dlp-lab/resolve/main/demo/src/normalize.py
- Command line
-
hf download hf://datasets/AriaAICompany/dlp-lab/demo/src/normalize.py
-
curl -L -o normalize.py https://huggingface.co/datasets/AriaAICompany/dlp-lab/resolve/main/demo/src/normalize.py
693 Bytes
| from __future__ import annotations | |
| import re | |
| DIGIT_TABLE = str.maketrans("۰۱۲۳۴۵۶۷۸۹٠١٢٣٤٥٦٧٨٩", "01234567890123456789") | |
| ZWNJ = "\u200c" | |
| NBSP = "\u00a0" | |
| HALF_SPACE_RE = re.compile(r"[\u200c\u200b\u00a0]") | |
| def fold_digits(text: str) -> str: | |
| return (text or "").translate(DIGIT_TABLE) | |
| def squeeze_spaces(text: str) -> str: | |
| return HALF_SPACE_RE.sub(" ", text or "") | |
| def compact(text: str) -> str: | |
| return fold_digits(squeeze_spaces(text or "")) | |
| def only_digits(text: str) -> str: | |
| return "".join(ch for ch in fold_digits(text or "") if ch.isdigit()) | |
| def strip_iban(text: str) -> str: | |
| return re.sub(r"[\s\-]", "", fold_digits(text or "")).upper() | |