numerizer
A Python module to convert natural language numerics into ints and floats. This is a port of the Ruby gem numerizer
Numerizer has been tested on Python 3.9, 3.10 and 3.11.
Installation
The numerizer library can be installed from PyPI as follows:
$ pip install numerizer
Usage
>>> from numerizer import numerize
>>> numerize('forty two')
'42'
>>> numerize('forty-two')
'42'
>>> numerize('four hundred and sixty two')
'462'
>>> numerize('one fifty')
'150'
>>> numerize('twelve hundred')
'1200'
>>> numerize('twenty one thousand four hundred and seventy three')
'21473'
>>> numerize('one million two hundred and fifty thousand and seven')
'1250007'
>>> numerize('one billion and one')
'1000000001'
>>> numerize('nine and three quarters')
'9.75'
>>> numerize('platform nine and three quarters')
'platform 9.75'
Using the SpaCy extension
Since version 0.2, numerizer is available as a SpaCy extension.
Any named entities of a quantitative nature within a SpaCy document can be numerized as follows:
>>> from spacy import load
>>> nlp = load('en_core_web_sm') # or load any other spaCy model
>>> doc = nlp('The projected revenue for the next quarter is over two million dollars.')
>>> doc._.numerize()
{the next quarter: 'the next 1/4', over two million dollars: 'over 2000000 dollars'}
Users can specify which entity types are to be numerized, by using the labels argument in the extension function, as follows:
>>> doc._.numerize(labels=['MONEY']) # only numerize entities of type 'MONEY'
{over two million dollars: 'over 2000000 dollars'}
The extension is available for tokens and spans as well.
>>> two_million = doc[-4:-2] # span corresponding to "two million"
>>> two_million._.numerize()
'2000000'
>>> quarter = doc[6] # token corresponding to "quarter"
>>> quarter._.numerized
'1/4'
Extras
For R users, a wrapper library has been developed by @amrrs. Try it out here.
Metadata
Release files for numerizer 0.2.4
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 |
|---|---|---|---|---|
| numerizer-0.2.4.tar.gz | 6.9 kB | Without provenance | Details for numerizer-0.2.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| numerizer-0.2.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for numerizer-0.2.4-py2.py3-none-any.whl |
Total release size: 14.2 kB
Release files / numerizer-0.2.4.tar.gz
| Download URL | numerizer-0.2.4.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2093849f05eb803ddb4643414a23cd1736c63112c98874cd40adebf5cf86de24
|
|
BLAKE2b-256 checksum How to use checksums |
bb63f8e3c8feb34814ed30d1fbea3c2785d277f58ee691f1e0f7f45a3ba6c43c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Release files / numerizer-0.2.4-py2.py3-none-any.whl
| Download URL | numerizer-0.2.4-py2.py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
4d5bb2630e5137cbcb1014069e6206e3c7748f7ee8dc18a0d22fbc1fcfd010e4
|
|
BLAKE2b-256 checksum How to use checksums |
bd333f516a6fc3c9c4d31e2baf0c22c0acc13d8d4bed56f5bb8e17f250775f27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for numerizer 0.2.4
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.