Skip to main content

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

Languages Supported

ovos-date-parser supports a wide array of languages, each with its own set of methods for handling natural language time expressions.

  • โœ… - supported
  • โŒ - not supported
  • ๐Ÿšง - imperfect placeholder, usually a language agnostic implementation or external library

Parse

Language extract_duration extract_datetime
az โœ… โœ…
ca โœ… โœ…
cs โœ… โœ…
da โœ… โœ…
de โœ… โœ…
en โœ… โœ…
es โœ… โœ…
gl โœ… ๐Ÿšง
eu โŒ โœ…
fa โœ… โœ…
fr โŒ โœ…
hu โŒ ๐Ÿšง
it โŒ โœ…
nl โœ… โœ…
pl โœ… โœ…
pt โœ… โœ…
ru โœ… โœ…
sv โœ… โœ…
uk โœ… โœ…

๐Ÿ’ก If a language is not implemented for extract_datetime then dateparser will be used as a fallback

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 โœ… โœ… ๐Ÿšง โœ…
gl โœ… โœ… ๐Ÿšง โœ…
eu โœ… โœ… โœ… โœ…
fa โœ… โœ… ๐Ÿšง โœ…
fr โœ… โœ… ๐Ÿšง โœ…
hu โœ… โœ… ๐Ÿšง โœ…
it โœ… โœ… ๐Ÿšง โœ…
nl โœ… โœ… ๐Ÿšง โœ…
pl โœ… โœ… ๐Ÿšง โœ…
pt โœ… โœ… ๐Ÿšง โœ…
ru โœ… โœ… ๐Ÿšง โœ…
sv โœ… โœ… ๐Ÿšง โœ…
sl โœ… โŒ ๐Ÿšง โœ…
uk โœ… โœ… ๐Ÿšง โœ…

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"

Related Projects

License

This project is licensed under the Apache 2.0 License

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

ovos-date-parser-0.6.4a1.tar.gz (148.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ovos_date_parser-0.6.4a1-py3-none-any.whl (179.1 kB view details)

Uploaded Python 3

File details

Details for the file ovos-date-parser-0.6.4a1.tar.gz.

File metadata

  • Download URL: ovos-date-parser-0.6.4a1.tar.gz
  • Upload date:
  • Size: 148.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for ovos-date-parser-0.6.4a1.tar.gz
Algorithm Hash digest
SHA256 cdfb383bc50dc8d1345ca70828bdbf1028a46aeb02be266d9ae16bf35a11badb
MD5 a34ffdc15ad0af763c29238d0c8c85aa
BLAKE2b-256 4d5deb84677dd5ff9c8826e68285ceafa1f91a553573952e797dde1d23fc28e6

See more details on using hashes here.

File details

Details for the file ovos_date_parser-0.6.4a1-py3-none-any.whl.

File metadata

File hashes

Hashes for ovos_date_parser-0.6.4a1-py3-none-any.whl
Algorithm Hash digest
SHA256 18bdd8aac272238941ae52682a77c66a4b2362cdd76c57e40cf8bc8b213af593
MD5 652f239833d59daaa6b7e2761aff5a58
BLAKE2b-256 259293deab5746ae25287e058dc93f6b78dcde06273521f5f36e70466c5eb8d3

See more details on using hashes here.

Supported by

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