Uzbek Text Normalization Library for TTS and NLP applications
Project description
UzTextNorm
Uzbek Text Normalization Library 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
- Integers:
- 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)
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]
)
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 # Main normalizer class
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uztextnorm-0.3.1.tar.gz.
File metadata
- Download URL: uztextnorm-0.3.1.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e80600a5ad4434a47e3f5478e236108f2643c459eafc85e355c9459eb68d4133
|
|
| MD5 |
84cab447d72ffcab5676757f193a4203
|
|
| BLAKE2b-256 |
c9ce1a38f13611d141bb4fce44ef3159f3e8f04e49b2b36ce5bfff3835c8d3cf
|
File details
Details for the file uztextnorm-0.3.1-py3-none-any.whl.
File metadata
- Download URL: uztextnorm-0.3.1-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61e3b7a05d33ce8e1d29959ae63888b916e04664e2ad0b5309d776e8df30d9f4
|
|
| MD5 |
0858ced982cd8fb4d34c03103f1a02fc
|
|
| BLAKE2b-256 |
5d1b7c48d0da403c247c03f5577f682be49f6c58e70c2e5cc330215efd77d21e
|