Convert word-form numbers to numerical values in Python.
- Convert word-form numbers to numerical values (integers and floats)
- Support for cardinal and ordinal numbers
- Support for English language (extensible to other languages)
- Handle complex number expressions
- Clean and maintainable codebase
- Type-safe implementation
- Comprehensive test coverage
- Python 3.11 or higher
pip install words2nums
from words2nums import Converter
from words2nums.core.converter import Locale
# Create converter with default locale (English)
converter = Converter()
# Or specify locale explicitly
converter = Converter(locale=Locale.ENGLISH) # Using enum
converter = Converter(locale="en") # Using string
# Cardinal numbers
print(converter.convert("twenty-three")) # Output: 23
print(converter.convert("one hundred and five")) # Output: 105
# Ordinal numbers
print(converter.convert("twenty-first")) # Output: 21
print(converter.convert("one hundred and first")) # Output: 101
print(converter.convert("thousandth")) # Output: 1000
# Decimal numbers
print(converter.convert("twenty-three point five")) # Output: 23.5
print(converter.convert("one point two five")) # Output: 1.25
# Complex expressions
print(converter.convert("one million two hundred thousand")) # Output: 1200000
print(converter.convert("two hundred and twenty-third")) # Output: 223
Full documentation is available at https://words2nums.readthedocs.io/
-
Clone the repository:
git clone https://github.com/hrimov/words2nums.git cd words2nums
-
Create a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows, use `.venv\Scripts\activate`
-
Install dependencies:
# For development (linting and testing) pip install -e ".[lint,test]" # For documentation generation pip install -e ".[docs]"
We welcome contributions! Please see our Contributing Guidelines for details.
This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.