Datasets:
Download country_laws_ir/tokenize.py from justicedao/ipfs_libya_laws_ir: direct link, hf CLI and curl.
- Browser
- Download file 518 Bytes
-
https://huggingface.co/datasets/justicedao/ipfs_libya_laws_ir/resolve/main/country_laws_ir/tokenize.py
- Command line
-
hf download hf://datasets/justicedao/ipfs_libya_laws_ir/country_laws_ir/tokenize.py
-
curl -L -o tokenize.py https://huggingface.co/datasets/justicedao/ipfs_libya_laws_ir/resolve/main/country_laws_ir/tokenize.py
518 Bytes
| """FTS5 unicode61 remove_diacritics=2-style tokenizer.""" | |
| from __future__ import annotations | |
| import re | |
| import unicodedata | |
| _TOKEN_RE = re.compile(r"[0-9A-Za-z]+", re.UNICODE) | |
| def fold_diacritics(text: str) -> str: | |
| if not text: | |
| return "" | |
| nfkd = unicodedata.normalize("NFKD", text) | |
| return "".join(ch for ch in nfkd if not unicodedata.combining(ch)).lower() | |
| def tokenize(text: str | None) -> list[str]: | |
| if not text: | |
| return [] | |
| return _TOKEN_RE.findall(fold_diacritics(str(text))) | |