Semantic is a Python library for extracting semantic information from text, including dates, numbers, mathematical equations, and unit conversions.
For each of these four semantic types, semantic provides a service module. Typical usage often looks like this:
#!/usr/bin/env python
from semantic.dates import DateService
service = DateService()
date = service.extractDate("On March 3 at 12:15pm...")
...
The full documentation can be found here, while the source code itself is also available on GitHub.
Installation
Installing semantic is simple:
$ pip install semantic
Features
semantic contains four main modules, each of which corresponds to a different semantic extractor.
Dates (date.py)
Useful for:
Extracting relative (e.g., “a week from today”) and absolute (e.g., “December 11, 2013”) dates from text snippets.
Converting date objects to human-ready phrasing.
Numbers (number.py)
Useful for:
Extracting numbers (integers or floats) from text snippets.
Converting numbers to human-readable strings.
Example usage:
#!/usr/bin/env python
from semantic.numbers import NumberService
service = NumberService()
print service.parse("Two hundred and six")
# 206
print service.parse("Five point one five")
# 5.15
print service.parse("Eleven and two thirds")
# 11.666666666666666
print service.parseMagnitude("7e-05")
# "seven to the negative five"
Math (solver.py)
Useful for performing mathematical operations expressed as words.
Example usage:
#!/usr/bin/env python
from semantic.solver import MathService
service = MathService()
print service.parseEquation("Log one hundred and ten")
# 4.70048
Units (units.py)
Useful for converting between units expressed as words.
Example usage:
#!/usr/bin/env python
from semantic.solver import ConversionService
service = ConversionService()
print service.convert("Seven and a half kilograms to pounds")
# (16.534, 'lbs')
print service.convert("Seven and a half pounds per square foot to kilograms per meter squared")
# (36.618, 'kg/m**2')
Testing
The test suite (test.py) contains tons of examples and use-cases for each of the four modules.
Requirements
The Dates, Numbers, and Math modules can run in isolation (i.e., without any dependencies), while the Units module requires quantities and Numpy.
License
MIT © Charles Marsh
Metadata
Release files for semantic 1.0.3
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 | |
|---|---|---|---|---|
| semantic-1.0.3.tar.gz | 15.2 kB | Without provenance | Details |
Release files / semantic-1.0.3.tar.gz
| Download URL | semantic-1.0.3.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bbc47dad03dddb1ba5895612fdfa1e43cfb3c497534976cebacd4f3684b505b4
|
|
BLAKE2b-256 checksum How to use checksums |
0e0c3673f66b77b06aedb3df7ff1166cf34e0e7fceed86a343b3e75283e2b687
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for semantic 1.0.3
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.