Skip to content

Ability to pass reference date context #74

@niedakh

Description

@niedakh

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:


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:
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:

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions