-
Notifications
You must be signed in to change notification settings - Fork 25
Description
I would like to be able to pass reference date to the builtin entity parser, just like in duckling or rustling. At the moment next friday matches the closest friday after parsing time. I would like to be able to get the closest friday to any arbitrary date when parsing next friday.
This is supported in rustling via the ResolverContext and could be also supported in the snips-ontology.
Two things are needed for this to work:
Replace:
| let context = ResolverContext::default(); |
with a
self.context property constructed based on provided datetime passed down to the rustling parser:| .parse_with_kind_order(&sentence.to_lowercase(), &context, &kind_order) |
Add an ISO reference datetime in constructor:
snips-nlu-ontology/platforms/snips-nlu-ontology-python/snips_nlu_ontology/builtin_entities.py
Line 115 in a5f0730
| def __init__(self, language): |
convert it to ISO date string property or anything else that can be parsed by chrono in rust and push it down the binding slide via:
snips-nlu-ontology/snips-nlu-ontology-parsers-ffi-macros/src/builtin_entity_parser.rs
Lines 25 to 34 in 50120f9
| pub fn create_builtin_entity_parser( | |
| ptr: *mut *const CBuiltinEntityParser, | |
| lang: *const libc::c_char, | |
| ) -> Result<()> { | |
| let lang = unsafe { CStr::from_ptr(lang) }.to_str()?; | |
| let lang = Language::from_str(&*lang.to_uppercase())?; | |
| let parser = BuiltinEntityParser::new(lang); | |
| let c_parser = CBuiltinEntityParser(parser.into_raw_pointer() as _).into_raw_pointer(); | |
to:
| impl BuiltinEntityParser { |
Then parse the string with chrono and set it up with:
let context = ResolverContext::new(Interval::starting_at(Moment(Local.ymd(year, month, day).and_hms(hour, minute, second)), Grain::Second));Is this somewhere on your todo list? Are you working on this? Would you consider implementing this or helping me get to a point where I can submit an acceptable PR?