2021-07-02 20:40:06 -05:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use regex::Regex;
|
|
|
|
|
|
|
|
lazy_static! {
|
2021-07-05 12:14:09 -05:00
|
|
|
// https://regex101.com/r/V9zYQu/1/
|
2021-07-02 20:40:06 -05:00
|
|
|
pub static ref HUMAN_REGEX: Regex = Regex::new(r"(?xi)
|
|
|
|
(?P<hour>
|
|
|
|
(?P<hnum>
|
2021-12-13 13:58:37 -06:00
|
|
|
(?P<half>half(\s+)a(n)?)|
|
2021-07-02 20:40:06 -05:00
|
|
|
(?P<hcase>a|an|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen)|
|
|
|
|
(?P<hdigit>one|two|three|four|five|six|seven|eight|nine)|
|
|
|
|
(?P<hten>ten|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety)|
|
|
|
|
(?P<hcomposed>
|
|
|
|
(?P<hcten>ten|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety)
|
|
|
|
.(?P<hcdigit>one|two|three|four|five|six|seven|eight|nine)
|
|
|
|
)|
|
|
|
|
(?P<htextualnum>\d+)
|
|
|
|
)
|
2021-07-03 15:53:56 -05:00
|
|
|
(\s+)?h(ou)?(r)?s?
|
2021-07-02 20:40:06 -05:00
|
|
|
)?
|
|
|
|
(?P<sep>\s*(,|and)?\s+)?
|
|
|
|
(?P<minute>
|
|
|
|
(?P<mnum>
|
|
|
|
(?P<mcase>a|an|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen)|
|
|
|
|
(?P<mdigit>one|two|three|four|five|six|seven|eight|nine)|
|
|
|
|
(?P<mten>ten|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety)|
|
|
|
|
(?P<mcomposed>
|
|
|
|
(?P<mcten>ten|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety)
|
|
|
|
.(?P<mcdigit>one|two|three|four|five|six|seven|eight|nine)
|
|
|
|
)|
|
|
|
|
(?P<mtextualnum>\d+)
|
|
|
|
)
|
2021-07-05 12:14:09 -05:00
|
|
|
(\s+)?m(in)?(ute?)?s?
|
2021-07-02 20:40:06 -05:00
|
|
|
)?
|
|
|
|
\s+ago
|
|
|
|
").unwrap();
|
|
|
|
|
|
|
|
pub static ref DATETIME_REGEX: Regex = Regex::new(r"(?xi)
|
|
|
|
(?P<year>\d{4}) # the year, mandatory
|
|
|
|
.
|
|
|
|
(?P<month>\d{2}) # the month, mandatory
|
|
|
|
.
|
|
|
|
(?P<day>\d{2}) # the day, mandatory
|
|
|
|
(. # a separator
|
|
|
|
(?P<hour>\d{2}) # the hour, optional
|
|
|
|
(. # a separator
|
|
|
|
(?P<minute>\d{2})? # the minute, optional
|
|
|
|
(. # a separator
|
|
|
|
(?P<second>\d{2}))?)?)? # the second, optional, implies minute
|
|
|
|
(?P<offset>
|
|
|
|
(?P<utc>Z)|((?P<sign>\+|-)(?P<ohour>\d{1,2}):(?P<omin>\d{2}))
|
|
|
|
)? # the offset, optional
|
|
|
|
").unwrap();
|
|
|
|
|
|
|
|
pub static ref HOUR_REGEX: Regex = Regex::new(r"(?xi)
|
|
|
|
(?P<hour>\d{1,2}) # the hour, mandatory
|
|
|
|
(. # a separator
|
|
|
|
(?P<minute>\d{2})? # the minute, optional
|
|
|
|
(. # a separator
|
|
|
|
(?P<second>\d{2}))?)? # the second, optional, implies minute
|
|
|
|
(?P<offset>
|
|
|
|
(?P<utc>Z)|((?P<sign>\+|-)(?P<ohour>\d{1,2}):(?P<omin>\d{2}))
|
|
|
|
)? # the offset, optional
|
|
|
|
").unwrap();
|
|
|
|
|
2021-12-13 13:58:37 -06:00
|
|
|
pub static ref NUMBER_VALUES: HashMap<&'static str, f64> = {
|
2021-07-02 20:40:06 -05:00
|
|
|
vec![
|
2021-12-13 13:58:37 -06:00
|
|
|
("a", 1.),
|
|
|
|
("an", 1.),
|
|
|
|
("ten", 10.),
|
|
|
|
("eleven", 11.),
|
|
|
|
("twelve", 12.),
|
|
|
|
("thirteen", 13.),
|
|
|
|
("fourteen", 14.),
|
|
|
|
("fifteen", 15.),
|
|
|
|
("sixteen", 16.),
|
|
|
|
("seventeen", 17.),
|
|
|
|
("eighteen", 18.),
|
|
|
|
("nineteen", 19.),
|
2021-07-02 20:40:06 -05:00
|
|
|
|
2021-12-13 13:58:37 -06:00
|
|
|
("one", 1.),
|
|
|
|
("two", 2.),
|
|
|
|
("three", 3.),
|
|
|
|
("four", 4.),
|
|
|
|
("five", 5.),
|
|
|
|
("six", 6.),
|
|
|
|
("seven", 7.),
|
|
|
|
("eight", 8.),
|
|
|
|
("nine", 9.),
|
2021-07-02 20:40:06 -05:00
|
|
|
|
2021-12-13 13:58:37 -06:00
|
|
|
("twenty", 20.),
|
|
|
|
("thirty", 30.),
|
|
|
|
("forty", 40.),
|
|
|
|
("fifty", 50.),
|
|
|
|
("sixty", 60.),
|
|
|
|
("seventy", 70.),
|
|
|
|
("eighty", 80.),
|
|
|
|
("ninety", 90.),
|
2021-07-02 20:40:06 -05:00
|
|
|
].into_iter().collect()
|
|
|
|
};
|
|
|
|
}
|