A library for converting numbers to words contextually.
Project description
MathSpell
MathSpell is a Python package for converting numbers into contextually appropriate words, such as "twenty-first century" for years or "two thousand and twenty-three" for general numbers.
Installation
-
Install the package:
pip install mathspell
-
Download the required spaCy language model:
python -m spacy download en_core_web_sm
-
Upgrade Pint to it's latest version if it is incompatible with the current version of numpy.
pip install --upgrade pint
Usage
After installation, you can use MathSpell to process text containing numbers. For example:
from mathspell import analyze_text
text = "This is the 21st century. I was born in 1995."
converted_text = analyze_text(text)
print(converted_text)
# Output: "This is the twenty-first century. I was born in nineteen ninety-five."
Further Examples
1. Year Conversion
from mathspell import analyze_text
input_text = "Something happened in 2021."
output = analyze_text(input_text)
print(output)
# Output: "Something happened in twenty twenty-one."
2. Ordinal Numbers
from mathspell import analyze_text
input_text = "This is my 3rd attempt to fix the bug."
output = analyze_text(input_text)
print(output)
# Output: "This is my third attempt to fix the bug."
3. Dates and Years
from mathspell import analyze_text
input_text = "My birthday is on 4th April, 1993."
output = analyze_text(input_text)
print(output)
# Output: "My birthday is on fourth April, nineteen ninety-three."
4. Quantities
from mathspell import analyze_text
input_text = "This contains 15 boxes."
output = analyze_text(input_text)
print(output)
# Output: "This contains fifteen boxes."
5. Handling Ordinal and Non-Ordinal Context
from mathspell import analyze_text
input_text = "This is the 1st floor, and the elevator can hold 5 people."
output = analyze_text(input_text)
print(output)
# Output: "This is the first floor, and the elevator can hold five people."
6. Temperature Conversion
from mathspell import analyze_text
input_text = "The temperature is expected to be 25 degrees tomorrow."
output = analyze_text(input_text)
print(output)
# Output: "The temperature is expected to be twenty-five degrees tomorrow."
7. Complex Sentence
from mathspell import analyze_text
input_text = "The 2nd prize was awarded in 2022 for the 10th time."
output = analyze_text(input_text)
print(output)
# Output: "The second prize was awarded in twenty twenty-two for the tenth time."
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mathspell-0.1.0.tar.gz.
File metadata
- Download URL: mathspell-0.1.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd21cdc2bd007cd12090b902a1fd0b77517daf294dcb9f7de415ac4b4ca851c4
|
|
| MD5 |
393d3db24836e283c5e5d32404bec42d
|
|
| BLAKE2b-256 |
d42803b974b430cda97c79f1804c48a326854ca0dd77b0606797867ed52fc292
|
File details
Details for the file mathspell-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mathspell-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c148baa48d6f67ef6b1447689e486aca54b808b9717f0552588d248218f8f0d1
|
|
| MD5 |
707bb45d8cda3a0c6209df44d2384816
|
|
| BLAKE2b-256 |
563f11bb2f420fb9a853dd8f7c02601976b1df03fd045448e692240cc2b6597d
|