UzTextNorm
Uzbek and Russian text normalization for TTS and NLP applications.
Features
- Unicode Normalization: Normalizes text to NFC form
- Cyrillic to Latin Transliteration: Automatic conversion of Uzbek Cyrillic to Latin script
- Number Expansion: Converts numbers to Uzbek words
- Integers:
123→bir yuz yigirma uch - Decimals:
3.14→uch butun o'n to'rt - Fractions:
3/4→to'rtdan uch - Currency:
10,000 so'm→o'n ming soʻm - Percentages:
15%→o'n besh foiz,9,8%→to'qqiz butun sakkiz foiz
- Integers:
- Phones and Identifiers: Read in their written groups
+998 90 123 45 67→plyus to'qqiz yuz to'qson sakkiz, to'qson, bir yuz yigirma uch, ...№ 1234-5678→raqam o'n ikki o'ttiz to'rt, ellik olti yetmish sakkiz
- Dates:
15 mart,2024 yildaand2020-2024-yillarread as ordinals - Punctuation Normalization: Standardizes punctuation and whitespace
- URL/Email Preservation: Protects URLs and emails from normalization
- Custom Rules: Support for custom pre/post processing rules
Installation
pip install uztextnorm
Usage
Basic Usage
from uztextnorm import UzbekTextNormalizer
# Create a normalizer instance
normalizer = UzbekTextNormalizer()
# Normalize text
text = "Narx: 10,000 so'm; 15% oshdi"
result = normalizer(text)
print(result)
# Output: "narx: o'n ming soʻm; o'n besh foiz oshdi"
Cyrillic to Latin Transliteration
text = "Ўзбекистон Республикаси"
result = normalizer(text)
print(result)
# Output: "o'zbekiston respublikasi"
Number Expansion
# Integers
normalizer("123") # "bir yuz yigirma uch"
# Decimals
normalizer("3.14") # "uch butun o'n to'rt"
# Fractions
normalizer("3/4") # "to'rtdan uch"
normalizer("1/2") # "yarim"
normalizer("2 3/4") # "ikki butun to'rtdan uch"
# Currency
normalizer("10,000 so'm") # "o'n ming soʻm"
normalizer("2,500 $") # "ikki ming besh yuz dollar"
# Percentages
normalizer("15%") # "o'n besh foiz"
Configuration Options
normalizer = UzbekTextNormalizer(
to_lower=True, # Convert to lowercase (default: True)
transliterate_cyrillic=True, # Transliterate Cyrillic (default: True)
script="legacy", # "legacy" (o'/g'/sh/ch) or "2026" (ö/ğ/ş/ç)
speak_urls=False, # "https://kun.uz" -> "kun nuqta uz"
expand_roman=True, # "XXI asr" -> "yigirma birinchi asr"
spell_leftover_digits=True, # "A350" -> "a uch yuz ellik"
custom_pre_rules=[], # Custom pre-processing functions
custom_post_rules=[] # Custom post-processing functions
)
Custom Processing Rules
def remove_hashtags(text: str) -> str:
return text.replace('#', '')
def add_period(text: str) -> str:
if not text.endswith('.'):
return text + '.'
return text
normalizer = UzbekTextNormalizer(
custom_pre_rules=[remove_hashtags],
custom_post_rules=[add_period]
)
Russian
pip install "uztextnorm[ru]"
from uztextnorm import RussianTextNormalizer
normalizer = RussianTextNormalizer()
normalizer("В 2024 году выручка выросла на 15% и составила 1 250 000 сум.")
# "В две тысячи двадцать четвёртом году выручка выросла на пятнадцать процентов
# и составила один миллион двести пятьдесят тысяч сумов."
normalizer("Звоните: +998 (90) 123-45-67, заказ № 1234-5678.")
# "Звоните: плюс девятьсот девяносто восемь, девяносто, сто двадцать три, сорок пять,
# шестьдесят семь, заказ номер двенадцать тридцать четыре, пятьдесят шесть семьдесят восемь."
Case is kept (to_lower=False by default) and punctuation, quotes and dashes
survive as written, since they are pause cues for a TTS reader. The options
are to_lower, speak_urls, spell_leftover_digits, custom_pre_rules and
custom_post_rules, as for Uzbek.
Languages
Every language is a pack registered under a code:
from uztextnorm import available_languages, get_normalizer, register_language
available_languages() # ("ru", "uz")
uz = get_normalizer("uz", to_lower=False)
ru = get_normalizer("ru")
# A new language is a factory returning a callable normalizer.
register_language("xx", lambda **options: my_normalizer(**options))
Packs are built from small stages over a language-neutral core
(uztextnorm.core): each stage does one job and receives the services it
needs -- a number speller, an inflector, word tables -- so it can be tested
with stand-ins and reused across languages.
Module Structure
uztextnorm/
├── __init__.py # Package initialization
├── constants.py # Constants and language data
├── utils.py # Utility functions
├── transliterator.py # Cyrillic-to-Latin conversion
├── tokenizer.py # Token shielding (URLs, emails)
├── numbers.py # Number expansion
├── normalizer.py # Uzbek normalizer
├── core/ # Language-neutral pipeline, shielding, registry
├── stages/ # Stages shared across languages (phones, IDs, cleanup)
└── languages/
├── uz/ # Uzbek pack (wraps UzbekTextNormalizer)
└── ru/ # Russian pack: speller, inflector, lexicon, stages
Requirements
- Python >= 3.10
Development
Clone the repository and install the development dependencies:
git clone https://gitlab.com/adizbek/uztextnorm.git
cd uztextnorm
pip install -e ".[dev]"
Run the test suite:
pytest
Format and lint:
black src tests
ruff check src tests
Build the distribution artifacts:
python -m build
Links
- PyPI: https://pypi.org/project/uztextnorm/
- Repository: https://gitlab.com/adizbek/uztextnorm
- Issues: https://gitlab.com/adizbek/uztextnorm/-/issues
- Changelog: CHANGELOG.md
Author
Adizbek Ergashev — adizbek1998@gmail.com
License
MIT License — see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Metadata
Release files for uztextnorm 0.6.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 | Provenance | Actions |
|---|---|---|---|---|
| uztextnorm-0.6.0.tar.gz | 57.3 kB | Without provenance | Details for uztextnorm-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| uztextnorm-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for uztextnorm-0.6.0-py3-none-any.whl |
Total release size: 136.3 kB
Release files / uztextnorm-0.6.0.tar.gz
| Download URL | uztextnorm-0.6.0.tar.gz |
|---|---|
| Size | 57.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f1f7567cc8326bdb136650ce800658f15d28d5620e31dc45190cf1c28493308
|
|
BLAKE2b-256 checksum How to use checksums |
4060cb688d5aa5bb8fed43b02ea06906bab8d8a6b103e7681d03ddf367a875ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / uztextnorm-0.6.0-py3-none-any.whl
| Download URL | uztextnorm-0.6.0-py3-none-any.whl |
|---|---|
| Size | 79.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8950cf3a2c900dc23edada0447515beb50c362801b76c662394bf47f749852a5
|
|
BLAKE2b-256 checksum How to use checksums |
9580e62622239e78c937ffc889b41f9da6b8b9191ef8a44d13adc8aac2426f4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for uztextnorm 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.