Skip to main content

A library for converting numbers to words contextually.

Reason this release was yanked:

breaking change

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

  1. Install the package:

    pip install mathspell
    
  2. Download the required spaCy language model:

    python -m spacy download en_core_web_sm
    

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mathspell-0.0.3.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mathspell-0.0.3-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file mathspell-0.0.3.tar.gz.

File metadata

  • Download URL: mathspell-0.0.3.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

Hashes for mathspell-0.0.3.tar.gz
Algorithm Hash digest
SHA256 04b33469c1db08ada060354d1cc938951d71b91e12e7dc7a28b78a75a912ca00
MD5 79c804cf7dd8db4ab5991471da785773
BLAKE2b-256 577821b58d6c212329f867bdee27a93ed563316ef64963a33be0a479940c63d5

See more details on using hashes here.

File details

Details for the file mathspell-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: mathspell-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for mathspell-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c4da6b9e94309f8ef29b68a3d6c21461d26d949586ec032c56d368afbc329f96
MD5 ef2f9fb62131908cb6b200b73eb322fe
BLAKE2b-256 fbed3eda076bc1cc9263c228224ea8b3ebb9afdde553735153f39c29a47b6994

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page