Download codigo/ignis/data/normalize.py from ViniciusKhan/Ignis-30M: direct link, hf CLI and curl.
- Browser
- Download file 724 Bytes
-
https://huggingface.co/ViniciusKhan/Ignis-30M/resolve/main/codigo/ignis/data/normalize.py
- Command line
-
hf download hf://ViniciusKhan/Ignis-30M/codigo/ignis/data/normalize.py
-
curl -L -o normalize.py https://huggingface.co/ViniciusKhan/Ignis-30M/resolve/main/codigo/ignis/data/normalize.py
724 Bytes
| """Normalização Unicode e limpeza de artefatos de texto.""" | |
| from __future__ import annotations | |
| import re | |
| import unicodedata | |
| _RE_CONTROLE = re.compile(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]") | |
| _RE_ESPACOS_MULTIPLOS = re.compile(r"[ \t]{2,}") | |
| _RE_LINHAS_MULTIPLAS = re.compile(r"\n{3,}") | |
| def normalizar_texto(texto: str, forma: str = "NFC") -> str: | |
| """Normaliza Unicode e espaços, preservando fórmulas e conteúdo técnico.""" | |
| texto = unicodedata.normalize(forma, texto) | |
| texto = _RE_CONTROLE.sub("", texto) | |
| texto = texto.replace("\r\n", "\n").replace("\r", "\n") | |
| texto = _RE_ESPACOS_MULTIPLOS.sub(" ", texto) | |
| texto = _RE_LINHAS_MULTIPLAS.sub("\n\n", texto) | |
| return texto.strip() | |