A package for extracting numeric values/ranges from strings.
Project description
c3-NumParse
This package provides a set of tools for parsing a number from a string. It currently suppports:
- Parsing numeric values (e.g. "2410")
- Parsing number words (e.g. "one hundred forty five thousand two hundred three")
- Parsing negative numbers (e.g "negative fifty five")
- Parsing mixed numeric values and number words (e.g. "4 million")
- Parsing numeric ranges (e.g. "five to 10")
- Parsing units (e.g. "five miles", "8 to 10 hours")
These strings get parsed into a new RangeValue
class which allows for ranges to be represented,
and any values in this form to be compared against each other.
Installation
pip install NumParse
Usage
from num_parse.NumParser import NumParser
num_parser = NumParser()
num_parser.parse_num("4 million") # returns 4000000
num_parser.parse_num("-135 thousand") # returns -135000
num_parser.parse_num("2 m") # returns 2 meter
num_parser.parse_num("five to six hours") # returns 5 to 6 hour
num_parser.parse_num("2 m") < num_parser.parse_num("2 in") # returns False
Unit Tests
In order to run the unit tests, navigate to the num_parse/tests
directory and run the following command:
pytest -q
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
NumParse-0.1.1.tar.gz
(37.7 kB
view details)
File details
Details for the file NumParse-0.1.1.tar.gz
.
File metadata
- Download URL: NumParse-0.1.1.tar.gz
- Upload date:
- Size: 37.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3476e37775dae3ca8fe594d9f1971088bb8aaae705fc83d4737cf46da6172c89 |
|
MD5 | f7856d1b2c67be08051dec2b59624b5c |
|
BLAKE2b-256 | 5bc97dfe11ea780be2c7d8b655c00cb2c77526bad85e24e5bfacf199913d9670 |