Skip to content

GhanaNLP/num2desc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

num2desc

Convert numbers, dates, unit abbreviations, and currency amounts in English text to their full descriptive word forms.

Useful as a preprocessing step before machine translation, TTS, or any NLP pipeline where raw digits and abbreviations should be spoken out.

Installation

pip install num2desc

Requires Python 3.10+ and depends on num2words.

Usage

from num2desc import normalize

# Standalone numbers
normalize("there are 42 items")
# → "there are forty-two items"

# Dates
normalize("born on January 15, 1990")
# → "born on the fifteenth of January in the year nineteen ninety"

normalize("on 15th March, 2023")
# → "on the fifteenth of March in the year twenty twenty-three"

# Ordinals
normalize("1st place, 2nd place, 3rd place")
# → "first place, second place, third place"

# Currency (symbols & codes)
normalize("cost $50")
# → "cost fifty US dollars"

normalize("cost GHS 200")
# → "cost two hundred Ghana cedis"

normalize("raised $2 million")
# → "raised two million US dollars"

# Percentages
normalize("rate is 25%")
# → "rate is twenty-five percent"

# Abbreviated units
normalize("run 5 km")
# → "run five kilometers"

normalize("weight 1.5 kg")
# → "weight one point five kilograms"

# All patterns in one call
normalize("On 5 July, 2024, GHS 1.5 million was allocated for 500 km of roads. That's 15% of the budget.")
# → "On the fifth of July in the year twenty twenty-four, one point five million Ghana cedis was allocated for five hundred kilometers of roads. That's fifteen percent of the budget."

Development

pip install -e ".[dev]"
pytest tests/

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages