Skip to main content

PyPI - Version PyPI - Python Version PyPI - Downloads codecov

abbr2words

Multilingual, context-aware abbreviation expansion for text normalization and speech.

This standalone package was extracted from the abbreviation framework and language registries in kokorog2p. It has no runtime dependencies and uses a flat package layout (no src/ directory).

Supported languages

  • Czech (cs)
  • German (de)
  • English (en)
  • Spanish (es)
  • French (fr)
  • Italian (it)
  • Dutch (nl)
  • Polish (pl)
  • Portuguese (pt)
  • Russian (ru)
  • Swedish (sv)
  • Turkish (tr)

Locale forms such as de-DE, en_GB, and pt-BR are accepted and currently map to their base-language registry.

Dutch, Polish, Russian, Swedish, and Turkish currently provide conservative abbreviation and reviewed numeric-unit registries. Their multilingual examples are abbreviation-only; full speech-number normalization remains limited to the optional examples configured for the original scenario languages.

Installation

python -m pip install abbr2words

For development:

python -m pip install -e ".[dev]"
pytest

API

from abbr2words import abbr2words

text = "Prof. Klein kommt ggf. am Fr."
print(abbr2words(text, lang="de"))
# Professor Klein kommt gegebenenfalls am Freitag

Context can be disabled:

abbr2words("Fr. Klein", lang="de", context=False)
# Freitag Klein

External linguistic annotations

abbr2words remains dependency-free. Applications that already tokenize and tag text can pass provider-neutral TokenAnnotation objects with character offsets and optional POS labels. spaCy is not installed or imported by abbr2words; see the external POS annotation guide and examples/spacy_pos.py. Bundled registries do not currently require POS labels; annotations are used by custom entries configured with POS guards. The provider-specific tag value is retained as metadata but is not currently evaluated.

Use an isolated mutable registry for project-specific entries:

from abbr2words import Expander

expander = Expander("de")
expander.add("KI", "Künstliche Intelligenz", case_sensitive=True)
print(expander("KI hilft."))

Consumers that need the shared language registry can use get_shared_expander() and reset_expanders(). Expander and get_expander() remain isolated mutable registries.

Command line

python -m abbr2words --lang de "Prof. Klein kommt ggf."
printf 'Prof. Klein kommt ggf.' | abbr2words --lang de

Scope

abbr2words expands registered abbreviations and a reviewed set of unit symbols when they occur after numeric quantities. It preserves numeric values and does not spell ordinary numbers, dates, or times, and does not perform unit conversion or currency realization. Unit support is not universal UCUM support. Use the public iter_unit_matches() API when a downstream semantic normalizer needs the original numeric lexeme, source span, and stable canonical quantity identity.

abbr2words recognizes and identifies quantity symbols; it does not decide how a complete numeric quantity is spoken. Number words, grammatical number, currency major/minor decomposition, and locale-specific spoken decimal policy belong to the consuming speech normalizer.

abbr2words("500 g", lang="en")
# "500 gram"

abbr2words("section g", lang="en")
# "section g"

Examples

The repository includes runnable examples for abbreviation-only expansion and for composing abbr2words with num2words:

python -m pip install "abbr2words[examples]"
python examples/abbreviations.py
python examples/full_text_demo.py --sample german

abbr2words itself expands abbreviations only. The optional examples show how to combine it with num2words for broader speech-text normalization, including output such as 500 g -> five hundred grams. The full-text demo is example code, not part of the stable public API. See examples/README.md for the complete command reference.

Versioning

The package version is derived from Git tags by setuptools-scm. Use tags in the form v0.2.0, v0.3.0, and so on; the corresponding package version is generated automatically during builds. A checkout without tags falls back to 0.2.2 for this additive release.

For a release, commit the changes, create an annotated tag, and build from that tag:

git tag -a v0.2.0 -m "Release 0.2.0"
uv build

License

Apache License 2.0. See LICENSE and NOTICE.

Download files

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

Source Distribution

abbr2words-0.2.3.tar.gz (122.2 kB view details)

Uploaded Source

Built Distribution

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

abbr2words-0.2.3-py3-none-any.whl (58.7 kB view details)

Uploaded Python 3

File details

Details for the file abbr2words-0.2.3.tar.gz.

File metadata

  • Download URL: abbr2words-0.2.3.tar.gz
  • Upload date:
  • Size: 122.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for abbr2words-0.2.3.tar.gz
Algorithm Hash digest
SHA256 4394829a8615bed6ce2cb649bc0c1bbf6228c85b1262585273f77f0e048efb42
MD5 e2cb67fb2a2d7c8651f8e054258fc4e4
BLAKE2b-256 e13dd8840b9042dab2470323907415b2971b69327a36735db39f04456b3f5eed

See more details on using hashes here.

File details

Details for the file abbr2words-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: abbr2words-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 58.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for abbr2words-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 63e5815af1cbfe183339ad806725f5dc407d86a38ea2746ea123a39fb76e18c7
MD5 dabfc39cd15c3ad194614e1226c74044
BLAKE2b-256 a8b16ff25a8292edc5b37e47ac328b7caaf6c1f9f10b53a3a8d815277473f790

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

This release

0.2.3 This release

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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