text-iron
Dependency-free Persian/multilingual text normalization for search and matching
(queries, titles, body content). One implementation, pinned by NORM_VERSION, so
text normalized at different times stays byte-identical — drift silently
breaks matching.
Use
from text_iron import normalize_query, normalize_title, normalize_content
normalize_query("Café كيك ۱۲۳") # -> "cafe کیک 123"
normalize_title("کتاب: جلد ۲") # -> "کتاب: جلد 2"
normalize_content("بند اول\n\nبند دوم") # -> keeps the paragraph break
The output is a matching / embedding key, not display text. Always keep the original around for display and snippets.
Pipelines
| function | scripts kept | punctuation | whitespace |
|---|---|---|---|
normalize_query |
Persian/Arabic + Latin | none (letters+digits key) | flattened to one line |
normalize_title |
all | sentence punctuation | flattened to one line |
normalize_content |
all | sentence punctuation | line/paragraph structure preserved |
All three share one folding core and are idempotent.
Components
Composable, single-purpose, pure: to_unicode_form, fold_persian_letters,
strip_arabic_diacritics, fold_latin_diacritics, normalize_digits,
to_lowercase, canonicalize_zwnj, filter_charset (via CharPolicy),
flatten_whitespace, normalize_content_whitespace, fingerprint. Build a new
pipeline by composing these, then pin a new NORM_VERSION.
Design decisions worth knowing
- Homophones (
س/ص/ث,ز/ذ/ض/ظ, …) are NOT folded — they are distinct letters and real spelling signal. - Hamza forms (
أ/إ/ؤ/ئ),ة,ۀare NOT folded — conservative default; folding raises recall. Flip infold_persian_letters/ the table if desired. - NFKC is used, which rewrites
m²→m2,½→1⁄2,①→1. Switch a pipeline's_fold(..., unicode_form="NFC")if a use case must keep those glyphs. - Query drops non-Persian/Latin scripts; content keeps every script. The
charset policy is the main knob (
CharPolicy).
Install
pip install text-iron
Test
uv run pytest tests # or:
python tests/test_text_iron.py
Metadata
Release files for text-iron 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| text_iron-1.0.0.tar.gz | 10.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| text_iron-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.4 kB
Release files / text_iron-1.0.0.tar.gz
| Download URL | text_iron-1.0.0.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
022375ab1eec915c092fcc7ed0f30b5e43c7f9a42d22bf65245b2df0830cab18
|
|
BLAKE2b-256 checksum How to use checksums |
7b171c08adba49a76863c6fbcbeb73102c0507435229f1526127bddc445bbb02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / text_iron-1.0.0-py3-none-any.whl
| Download URL | text_iron-1.0.0-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a8f88b655fa357c937e2518b2fc4ec87603f07836c2cbcdc06c68787e6a01c9
|
|
BLAKE2b-256 checksum How to use checksums |
1ef8e4463f8b80f7908aea56ced841573180e515483fb0d5622fc7ddd5039f40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|