Skip to main content

Common Natural Language Processing Tasks for Python

Project description

https://badge.fury.io/py/semantic.png

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.units 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

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

semantic3-1.0.2.tar.gz (14.8 kB view details)

Uploaded Source

File details

Details for the file semantic3-1.0.2.tar.gz.

File metadata

  • Download URL: semantic3-1.0.2.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for semantic3-1.0.2.tar.gz
Algorithm Hash digest
SHA256 1bd33892dee8b637222570f90e71dad47da1235fc1904eaff7c1f153449d2d41
MD5 bb5598af5827125c24a2854eafe329b1
BLAKE2b-256 55db64642ec40db6547485894bd58946bb01343c4ec8411ca8baf07607cb28f0

See more details on using hashes here.

Supported by

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