Skip to main content

UzTextNorm

PyPI version Python versions License: MIT

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: 123bir yuz yigirma uch
    • Decimals: 3.14uch butun o'n to'rt
    • Fractions: 3/4to'rtdan uch
    • Currency: 10,000 so'mo'n ming soʻm
    • Percentages: 15%o'n besh foiz
  • 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]
)

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

Author

Adizbek Ergashevadizbek1998@gmail.com

License

MIT License — see LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uztextnorm-0.5.2.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uztextnorm-0.5.2-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file uztextnorm-0.5.2.tar.gz.

File metadata

  • Download URL: uztextnorm-0.5.2.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for uztextnorm-0.5.2.tar.gz
Algorithm Hash digest
SHA256 0a76c35947b78c3aa8b9025205b96c1cfe2bb3aa4230f0e33f312b6607167e7d
MD5 60ad24d94bb0de7adb3b5f90d3e8e855
BLAKE2b-256 5a25fde1acfdb40f19ddcf460b070d7073e2505a1b7c01fd94fc1c246cb11012

See more details on using hashes here.

File details

Details for the file uztextnorm-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: uztextnorm-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for uztextnorm-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 738f846252ed3c04714a647d0854d95ab38afac701dfb593cac497ce906e0717
MD5 9ba3a5e6927cd3544d06cae03ff2a35e
BLAKE2b-256 2c7d0305bd4a14cb35089d45ec23f89546a9f4f3be773e4fcf8942fe3ca687b0

See more details on using hashes here.

Release history Release notifications | RSS feed

0.5.3

2 files

This release

0.5.2 This release

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page