Semantic
A Python library for extracting semantic information from text, such as dates and numbers.
Install / Use
/learn @charliermarsh/SemanticREADME
Semantic
Semantic is a Python library for extracting semantic information from text, such as dates and numbers. Full documentation is available on PyPI, with a list of primary features and uses-cases below.
Installation
Installing semantic is simple:
$ pip install semantic
Features
Semantic consists of four main modules, each of which corresponds to a different semantic extractor. The test suite (test.py) contains tons of examples for each of the four modules, but some sample use-cases are described below.
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')
Dependencies
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
Related Skills
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。


