OpenVoiceOS's multilingual text parsing and formatting library
Project description
ovos-date-parser
ovos-date-parser
is a comprehensive library for multilingual date and time parsing, extraction, and formatting,
designed to handle a range of human-readable date, time, and duration expressions.
Features
- Date and Time Extraction: Extract specific dates and times from natural language phrases in various languages.
- Duration Parsing: Parse phrases that indicate a span of time, such as "two hours and fifteen minutes."
- Friendly Time Formatting: Format time for human-friendly output, supporting both 12-hour and 24-hour formats.
- Relative Time Descriptions: Generate relative descriptions (e.g., "tomorrow," "in three days") for given dates.
- Multilingual Support: Includes extraction and formatting methods for multiple languages, such as English, Spanish, French, German, and more.
Installation
pip install ovos-date-parser
Usage
Date and Time Extraction
Extract specific dates and times from a phrase. This function identifies date-related terms in natural language and returns both the datetime object and any remaining text.
from ovos_date_parser import extract_datetime
result = extract_datetime("Meet me next Friday at 3pm", lang="en")
print(result) # (datetime object, "at 3pm")
Duration Extraction
Identify duration phrases in text and convert them into a timedelta
object. This can parse common human-friendly
duration expressions like "30 minutes" or "two and a half hours."
from ovos_date_parser import extract_duration
duration, remainder = extract_duration("It will take about 2 hours and 30 minutes", lang="en")
print(duration) # timedelta object
print(remainder) # "about"
Formatting Time
Generate a natural-sounding time format suitable for voice or display in different languages, allowing customization for speech or written text.
from ovos_date_parser import nice_time
from datetime import datetime
dt = datetime.now()
formatted_time = nice_time(dt, lang="en", speech=True, use_24hour=False)
print(formatted_time) # "three o'clock"
Relative Time Descriptions
Create relative phrases for describing dates and times in relation to the current moment or a reference datetime.
from ovos_date_parser import nice_relative_time
from datetime import datetime, timedelta
relative_time = nice_relative_time(datetime.now() + timedelta(days=1), datetime.now(), lang="en")
print(relative_time) # "tomorrow"
Languages Supported
ovos-date-parser
supports a wide array of languages, each with its own set of methods for handling natural language
time expressions.
Parse
Language | extract_duration |
extract_datetime |
---|---|---|
az | ✅ | ✅ |
ca | ❌ | ✅ |
cs | ✅ | ✅ |
da | ❌ | ✅ |
de | ✅ | ✅ |
en | ✅ | ✅ |
es | ✅ | ✅ |
eu | ❌ | ✅ |
fa | ✅ | ✅ |
fr | ❌ | ✅ |
hu | ❌ | ❌ |
it | ❌ | ✅ |
nl | ✅ | ✅ |
pl | ✅ | ✅ |
pt | ✅ | ✅ |
ru | ✅ | ✅ |
sv | ✅ | ✅ |
uk | ✅ | ✅ |
Format
Language | nice_date nice_date_time nice_day nice_weekday nice_month nice_year get_date_strings |
nice_time |
nice_relative_time |
nice_duration |
---|---|---|---|---|
az | ✅ | ✅ | ✅ | ✅ |
ca | ✅ | ✅ | ✅ | ✅ |
cs | ✅ | ✅ | ✅ | ✅ |
da | ✅ | ✅ | ✅ | ✅ |
de | ✅ | ✅ | ✅ | ✅ |
en | ✅ | ✅ | ✅ | ✅ |
es | ❌ | ✅ | ✅ | ✅ |
eu | ✅ | ✅ | ✅ | ✅ |
fa | ✅ | ✅ | ✅ | ✅ |
fr | ✅ | ✅ | ✅ | ✅ |
hu | ✅ | ✅ | ✅ | ✅ |
it | ✅ | ✅ | ✅ | ✅ |
nl | ✅ | ✅ | ✅ | ✅ |
pl | ✅ | ✅ | ✅ | ✅ |
pt | ✅ | ✅ | ✅ | ✅ |
ru | ✅ | ✅ | ✅ | ✅ |
sv | ✅ | ✅ | ✅ | ✅ |
sl | ✅ | ❌ | ✅ | ✅ |
uk | ✅ | ✅ | ✅ | ✅ |
Related Projects
- ovos-number-parser - for handling numbers
- ovos-lang-parser - for handling languages
- ovos-color-parser - for handling colors
License
This project is licensed under the Apache 2.0 License
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
Built Distribution
File details
Details for the file ovos-date-parser-0.2.1.tar.gz
.
File metadata
- Download URL: ovos-date-parser-0.2.1.tar.gz
- Upload date:
- Size: 120.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e47d48f06514b86f655b2963fb1cf88b6c93102994c681742e382779e3e9e7f6 |
|
MD5 | a71c870903ae725c989165a9570fc5c5 |
|
BLAKE2b-256 | d2b00f2b367a55ca92578b02c58ac8234424ab2db53aa65e325043cf210b38ad |
File details
Details for the file ovos_date_parser-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: ovos_date_parser-0.2.1-py3-none-any.whl
- Upload date:
- Size: 172.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c07416cc1ab8f356ad0afb2d73dcc3b9f2933c0aa4035c8271b2fabdb8fe4db |
|
MD5 | 3fff1c6e3127b1a9c9fcb4a7cf0b150a |
|
BLAKE2b-256 | d49aee2c589e9fdf75ac07197223781a75a7455bc38f1eff8265d0e1f278f511 |