#nlp #date-time #parser #time-parser #natural #event #english-language

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

#167 in Programming languages

Download history 527/week @ 2023-11-20 496/week @ 2023-11-27 409/week @ 2023-12-04 290/week @ 2023-12-11 376/week @ 2023-12-18 442/week @ 2023-12-25 421/week @ 2024-01-01 393/week @ 2024-01-08 418/week @ 2024-01-15 353/week @ 2024-01-22 754/week @ 2024-01-29 320/week @ 2024-02-05 320/week @ 2024-02-12 550/week @ 2024-02-19 649/week @ 2024-02-26 817/week @ 2024-03-04

2,362 downloads per month
Used in 3 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
~72K SLoC