event_parser 0.1.0

Rust NLP library for parsing English natural language into icalendar events
Documentation

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};

# fn equal(actual: Event, expected: Event) -> bool {
#     return true
# }

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));

Example: Doctor's Appointment

The crate parses events relative to the current local time, meaning it's timezone sensitive and allows for events to be parsed without a particular date. Specifying a date like "tomorrow" or "next friday" is enough to determine the date on which that event is supposed to take place.

Additionally, if no end time is given for an event, the event duration defauls to 1 hour (similar to Google Calendar).

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

# fn equal(actual: Event, expected: Event) -> bool {
#     return true
# }

let event = to_event("4pm Doctor's Appointment tomorrow");
let expected_event = Event::new()
.summary("Doctor's Appointment")
.starts(Local::today().and_hms(16, 0, 0) + Duration::days(1))
.ends(Local::today().and_hms(17, 0,0 ) + Duration::days(1))
.done();
assert!(equal(event, expected_event));

Example: Printing

Event Parser also provides a pretty_print function to print the iCalendar Events that it parses out. This is a convenience function for using this crate in command line tools to be able to print events to the user.

use event_parser::{to_event, pretty_print};
use icalendar::{Component, Event};

let event = to_event("Flight on saturday at noon");
pretty_print(event);

Output:

date: 2020-04-25T12:00:00Z
Event: "Flight"
12:00pm April 25 2020 - 01:00pm April 25 2020