forked from charliermarsh/semantic
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathREADME.txt
More file actions
116 lines (71 loc) · 2.83 KB
/
README.txt
File metadata and controls
116 lines (71 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
===========
Semantic
===========
.. image:: https://badge.fury.io/py/semantic.png
:target: http://badge.fury.io/py/semantic
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 <https://pythonhosted.org/semantic/>`_, while the source code itself is also available on `GitHub <https://github.com/crm416/semantic>`_.
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 <https://pypi.python.org/pypi/quantities>`_ and `Numpy <http://www.numpy.org>`_.
License
=======
MIT © `Charles Marsh <http://www.princeton.edu/~crmarsh>`_