Skip to main content

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: 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)
    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.8

License

MIT License

Contributing

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

Continuous Integration & Publishing

This project ships with a GitLab CI pipeline configured in .gitlab-ci.yml. The pipeline runs on pushed branches and merge requests, executes the test-suite, and, when a git tag is pushed, builds release artifacts and uploads them to both PyPI and the GitLab Package Registry.

Required CI/CD variables

Add the following variables in the project settings under Settings → CI/CD → Variables:

  • PYPI_API_TOKEN – a PyPI token with the ability to publish the project (__token__ style token). The publish job is skipped if this variable is not present.

No extra configuration is required for the GitLab Package Registry publishing job; it uses the built-in CI_JOB_TOKEN. Ensure that the token’s default permissions are kept (read_registry/write_registry).

Release workflow

  1. Ensure tests pass locally: python -m pip install .[dev] && pytest.
  2. Bump the version in pyproject.toml.
  3. Commit the change and create an annotated tag matching the new version, e.g. git tag -a v0.2.0 -m "Release v0.2.0".
  4. Push the branch and tag: git push origin main --tags (replace main with the relevant branch).

The CI pipeline triggered by the tag will build the package once and publish it to both registries.

Project details


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.3.0.tar.gz (14.2 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.3.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: uztextnorm-0.3.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for uztextnorm-0.3.0.tar.gz
Algorithm Hash digest
SHA256 827f488944b762d2a6845808aff1a18068bda6bc5c4da66c617aff021ecf2a4d
MD5 8aea9c4e8c75dd393a01d2d7ab6a43f2
BLAKE2b-256 fbbcb85a5985e4d64891385d90794a7d263d6baa2f7a2bb4098095c80fa4f076

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uztextnorm-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for uztextnorm-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 678c0eaee3df44e9cb3853f2c4362d754b40309bc676be0f4748ca0e43913031
MD5 896e50b321d798d30ae9a366cc703dbd
BLAKE2b-256 b1e15b0c81409373265d3d48bad878cf85c3115ae8f2c136af5e976ffc4bd09b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page