Duckling (Rust)
A Rust port of Facebook's Duckling — a library for parsing natural language into structured data.
Given a string like "tomorrow at 3pm" or "42 degrees fahrenheit", Duckling extracts "dimensions" such as URLs and times that may be of interest.
Usage
use ;
use ;
let locale = new;
let context = Context ;
let options = default;
// Time — "tomorrow at 3pm" parses as a naive (wall-clock) time
let results = parse;
assert_eq!;
// Temperature
let results = parse;
assert_eq!;
// Numerals
let results = parse;
assert_eq!;
Supported dimensions
Time, Numeral, Ordinal, Temperature, Distance, Volume, Quantity, AmountOfMoney, Duration, Email, PhoneNumber, Url, CreditCardNumber.
Time: instant vs naive
Time values distinguish between absolute instants and wall-clock/calendar times:
- Naive —
"5 pm","tomorrow","March 15th"— wall-clock times with no timezone assumption - Instant —
"now","in 2 hours","5 pm EST"— pinned to a specific UTC moment
// Naive: no timezone baked in
TimeValue::Single(TimePoint::Naive { value: NaiveDateTime, grain })
// Instant: absolute UTC moment
TimeValue::Single(TimePoint::Instant { value: DateTime<Utc>, grain })
An explicit timezone (e.g. "3pm CET") promotes any naive time to an instant.
Acknowledgements
This is a Rust rewrite of facebook/duckling, originally written in Haskell.