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.
Supported dimensions
Time, Numeral, Ordinal, Temperature, Distance, Volume, Quantity, AmountOfMoney, Duration, Email, PhoneNumber, Url, CreditCardNumber.
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;
if let Time = &results.value else
// Temperature
let results = parse;
assert_eq!;
// Numerals
let results = parse;
assert_eq!;
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 { value: TimePoint::Naive { value: NaiveDateTime, grain }, values: Vec<TimePoint> }
// Instant: absolute UTC moment
TimeValue::Single { value: TimePoint::Instant { value: DateTime<Utc>, grain }, values: Vec<TimePoint> }
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.