Find every number in a text: exact values as digit strings, kinds and character spans.
Maintained. Last release today, commits in 3 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install numtagREADME as published on PyPI with version 0.54.4a1.
numtag
numtag finds every number in a text. For each number it gives the exact words, their character offsets, an exact value, the kind of number and how it is written. It reads number words ("duas dúzias"), digits ("1.234,5") and both together ("2 milhões"), in more than 50 lexicons.
Try it in the browser: TigreGotico/numtag Space.
Install
numtag needs Python 3.11 or later.
uv pip install --prerelease=allow numtag
Quickstart
from numtag import tag_numbers
for m in tag_numbers("Comprou duas dúzias de ovos e ganhou um milhão de euros.", "pt-PT"):
print(m.char_span, repr(m.text), m.value, m.kind.value)
(8, 19) 'duas dúzias' 24 cardinal
(37, 46) 'um milhão' 1000000 cardinal
A value is a canonical digit string such as "24", "2.5" or "1/3", never an int or a float. The span slices the original text.
Documentation
| Page | What you get there |
|---|---|
| docs/index.md | The map of the documentation |
| docs/getting-started.md | A walk-through of the first calls and the common tasks |
| docs/api.md | Every public name |
| docs/values.md | The value strings and how to convert them |
| docs/number-scale.md | Long and short scale |
| docs/confidence-and-homographs.md |