Download ocr/anonymization/normalization.py from Leon4gr45/agent-0: direct link, hf CLI and curl.
- Browser
- Download file 411 Bytes
-
https://huggingface.co/spaces/Leon4gr45/agent-0/resolve/main/ocr/anonymization/normalization.py
- Command line
-
hf download hf://spaces/Leon4gr45/agent-0/ocr/anonymization/normalization.py
-
curl -L -o normalization.py https://huggingface.co/spaces/Leon4gr45/agent-0/resolve/main/ocr/anonymization/normalization.py
411 Bytes
| """One reversible source-coordinate view for hyphenated OCR line wraps.""" | |
| import re | |
| LINE_WRAP = re.compile(r"(?<=[^\W\d_])-\r?\n(?=[^\W\d_])", re.UNICODE) | |
| def dehyphenate(text): | |
| removed = {i for match in LINE_WRAP.finditer(text) for i in range(match.start(), match.end())} | |
| positions = tuple(i for i in range(len(text)) if i not in removed) | |
| return "".join(text[i] for i in positions), positions | |