word2num 💬 → 🔢
word2num is a Python package for converting numbers expressed in natural language to numerical values. It supports:
- Fractions
- Decimals
- Negative values
- Large numbers into the quintillions
- Digit sequences
- Fuzzy string matching
Table of Contents
🛠️ Installation
To use word2num, you must first install it. You can do this using pip by running the following command in your terminal:
pip install word2num
💻 Usage
Once installed, you can use word2num to convert numbers expressed in natural language to numerical values. To parse a single string, use the word2num convenience function:
from word2num import word2num
word2num("fifty-seven thousand four hundred and twenty-one") # 57421
If you need to parse multiple strings, you can create your own instance of Word2Num and call its parse method:
from word2num import Word2Num
w2n = Word2Num()
w2n.parse("one hundred and one") # 101
w2n.parse("seventeen billion") # 17000000000
w2n.parse("negative eight") # -8
w2n.parse("half") # 0.5
w2n.parse("one and three quarters") # 1.75
w2n.parse("one three three seven") # 1337
Note that these functions will return None if a valid numerical value couldn't be interpreted.
🐻 Fuzzy String Matching
word2num uses fuzzy string matching to help parse misspelled number words.
Default Fuzzy Threshold
By default, word2num uses a fuzzy threshold of 80, which means that it will match a word to a number if the fuzzy score is 80 or higher.
Custom Fuzzy Threshold
You can change the fuzzy threshold by passing a fuzzy_threshold parameter to the word2num function or to the Word2Num class constructor:
# Using the word2num function
word2num("soxteeeen", fuzzy_threshold=60) # [16]
# Using the Word2Num class
w2n = Word2Num(fuzzy_threshold=60)
w2n.parse("twoo hunrdered and twienty-too") # [222]
Disable Fuzzy Matching
To disable fuzzy matching (exact matching only), you can set the fuzzy_threshold to 100:
w2n = Word2Num(fuzzy_threshold=100)
w2n.parse("two hundered and twinty-two") # None
🌐 Language Support
- English
- Spanish
We'd love to add support for other languages. Contributions are more than welcome, so if you're interested in contributing, see the "Contributing" section below!
🤝 Contributing
Contributions to word2num are more than welcome! If you'd like to contribute, please follow these guidelines:
- Make sure the tests pass by running
pytestin the root directory of the repository. - If appropriate, add new tests to cover your changes.
- Follow the existing code style and conventions.
- Create a pull request with your changes.
📃 License
word2num is released under the MIT License. See LICENSE.txt for more information.
Metadata
Release files for word2num 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| word2num-0.1.2.tar.gz | 13.4 kB | Without provenance | Details for word2num-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| word2num-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for word2num-0.1.2-py3-none-any.whl |
Total release size: 30.7 kB
Release files / word2num-0.1.2.tar.gz
| Download URL | word2num-0.1.2.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9cf7a73b0207a0c4113b1272811743982c83f13be03639ee800333cc0e5a942
|
|
BLAKE2b-256 checksum How to use checksums |
b01974026e941148de9f21a3bf4b78c264eeb4eae57079887c39e392329a41c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / word2num-0.1.2-py3-none-any.whl
| Download URL | word2num-0.1.2-py3-none-any.whl |
|---|---|
| Size | 17.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c30ce2631552857415ebd2aaf8419c9adbd1b26e28aa7299b839bed94dad86a
|
|
BLAKE2b-256 checksum How to use checksums |
9791c1f0557d5516ec34c3f1a263b00923fd5607848af321e0efe38130411454
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for word2num 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.