#date-time #date-parser

date_time_parser

Rust NLP library for parsing English natural language into dates and times

3 unstable releases

0.2.0 Aug 29, 2022
0.1.1 May 23, 2021
0.1.0 Apr 21, 2020

#96 in #date-time

Download history 446/week @ 2024-06-07 553/week @ 2024-06-14 575/week @ 2024-06-21 461/week @ 2024-06-28 366/week @ 2024-07-05 484/week @ 2024-07-12 521/week @ 2024-07-19 412/week @ 2024-07-26 248/week @ 2024-08-02 306/week @ 2024-08-09 319/week @ 2024-08-16 380/week @ 2024-08-23 626/week @ 2024-08-30 415/week @ 2024-09-06 338/week @ 2024-09-13 363/week @ 2024-09-20

1,842 downloads per month
Used in 4 crates

MIT license

36KB
596 lines

Event Parser

Natural language date, time and event parsing libraries for Rust

Build crates.io

Event Parser contains an date and time natural language parsing library, and event parsing library, as well as a client that demonstrates how to leverage these crates for a simple command-line tool. Written in Rust, the libraries build on the chrono and regex crates to deliver a library that provides more extensive coverage of natural language statements.

Date Time Parser: Rust NLP Library

It aims to parse unstructered text into NaiveDate and NaiveTime formats.

  • Date Time Parser has the ability to be timezone aware, but defaults to UTC.
  • Allows for parse to be relative to current date/time, or relative to a custom date/time.

Usage

Put this in your Cargo.toml:

[dependencies]
date_time_parser = "0.1.0"

Then put this in your crate root:

extern crate date_time_parser;

Example: Find a Date

General use of this package involves passing English natural language that includes a date to the DateParser struct to parse the expression. If a date is found, it will parse the expression into the NaiveDate format.

use date_time_parser::DateParser;
use chrono::NaiveDate;

let date = DateParser::parse("Lunch on June 5th");
assert_eq!(date, Some(NaiveDate::from_ymd(2020, 6, 5)));

For more examples and usage, please refer to the docs.

Event Parser: Rust NLP Library

Aims to parse unstructered text into iCalendar Events.

  • Parses text into events with a date and time relative to the local time.
  • Event Parser defaults to be timezone aware.
  • Leverages the crate date_time_parser for parsing out the dates and time of events.

Usage

Put this in your Cargo.toml:

[dependencies]
event_parser = "0.1.0"

Then put this in your crate root:

extern crate event_parser;

Example: Dinner at 7pm

Pass English natural language that describes an event to the to_event function to parse the expression. It will parse the expression into the iCalendar Events format.

If applicable, the event will have a start and end time, or be classified as an all-day event. Addtionally, a date will be parsed for the event, defaulting to the current day if no date is found. The event will also have a summary (the name of the event), if one is given.

use event_parser::to_event;
use chrono::{Duration, Local};
use icalendar::{Component, Event};
 

let event = to_event("Dinner at 7");
let expected_event = Event::new()
    .summary("Dinner")
    .starts(Local::today().and_hms(19, 0, 0))
    .ends(Local::today().and_hms(19, 0, 0) + Duration::hours(1))
    .done();
assert!(equal(event, expected_event));

For more examples and usage, please refer to the docs.

Command Line Tool

To play around with what is possible with the event_parser library, we've provided a command-line tool to be able to test different inputs easily. Simply download the repo and from the root of the project run cargo run and type an natural English language event to see how it is parsed!

Development setup

Install the Rust programming language, and then clone this repository.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
git clone https://github.com/isaacrlee/event-parser.git

To run the program and easily play with inputs:

cargo run

To run the test suite:

cargo test --all

License

License: MIT

The MIT License

Distributed under the MIT license. See LICENSE for more information.
Copyright (c) 2020 Isaac Lee and Alex Grimes

Dependencies

~3–4.5MB
~71K SLoC