Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference time support #78

Closed
wants to merge 21 commits into from
Closed

Reference time support #78

wants to merge 21 commits into from

Conversation

niedakh
Copy link

@niedakh niedakh commented Jul 17, 2018

This PR adds an additional parameter to provide a reference timestamp for datetimes detected by rustling.

@niedakh
Copy link
Author

niedakh commented Jul 17, 2018

note that my Cargo.ml repository url changes should be reverted before merging

Copy link
Collaborator

@adrienball adrienball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this PR, I made some comments.

snips-nlu-ontology-parsers-ffi-macros = { git = "https://github.com/snipsco/snips-nlu-ontology", branch = "develop" }
snips-nlu-ontology = { git = "https://github.com/niedakh/snips-nlu-ontology", branch = "develop" }
snips-nlu-ontology-ffi-macros = { git = "https://github.com/niedakh/snips-nlu-ontology", branch = "develop" }
snips-nlu-ontology-parsers-ffi-macros = { git = "https://github.com/niedakh/snips-nlu-ontology", branch = "develop" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a script (.travis/install.sh) which is run during the CI to replace these dependencies with relative paths.

That means you can discard these changes :)

@@ -25,17 +28,20 @@ lazy_static! {
}

impl BuiltinEntityParser {
pub fn new(lang: Language) -> Self {
pub fn new(lang: Language, reference_timestamp: i64) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the reference_timestamp should be provided as a parameter of the extract_entities method, in order to avoid the creation of multiple BuiltinEntityParser.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, this parameter should be optional.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, I'll move this to extract_entities in a moment. I'm wondering on which tier it needs to be optional. It already is optional in the python binding, I can make it optional using Option in rust, but it will have to be "non-optional" in the ffi. Does that sound ok?

@@ -107,7 +113,11 @@ impl BuiltinEntityParser {
sentence: &str,
filter_entity_kinds: Option<&[BuiltinEntityKind]>,
) -> Vec<BuiltinEntity> {
let context = ResolverContext::default();
// don't cover global nlu_ontology::Grain
use rustling_ontology::{Grain, Interval};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why you do the import here.

@@ -101,7 +104,7 @@ pub fn extract_entity(
};
let opt_filters = opt_filters.as_ref().map(|vec| vec.as_slice());

Ok(parser.extract_entities(sentence, opt_filters))
Ok(parser.extract_entities(sentence, Some(reference_timestamp), opt_filters))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should make reference_timestamp optional here through a -1 value, not ideal but would let the rust code handle the default logic. The ffi may be used by other bindings than just the python one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I went with a i64:MIN for default value, instead of -1, it is much less probable that someone wants to set reference time to 1901-12-13 20:45:52 than 1969-12-31 23:59:59.

);
let context = ResolverContext::new(
Interval::starting_at(Moment(reference_datetime), rustling_ontology::Grain::Second)
);
Copy link
Collaborator

@adrienball adrienball Jul 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather go for the following, in order to reduce the number of created objects and let rustling define the default behavior:

let context = reference_timestamp
            .map(|ts|
                ResolverContext::new(
                    Interval::starting_at(Moment(Local.timestamp(ts, 0)), rustling_ontology::Grain::Second)))
            .unwrap_or_else(|| ResolverContext::default());

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@niedakh
Copy link
Author

niedakh commented Jul 25, 2018

@adrienball i've fixed the code, added a default value case (i64::min), all test pass, do you have a moment for another iteration of the review?

@adrienball
Copy link
Collaborator

Hey @niedakh ,
After re-reading your PR, I'm thinking that, instead of updating the current API we should add a new one which would be something like:

pub fn extract_entity_with_context(
     ptr: *const CBuiltinEntityParser,
     sentence: *const libc::c_char,
     filter_entity_kinds: *const CStringArray,
     reference_timestamp: i64,
 ) -> Result<Vec<BuiltinEntity>> 

This has two advantages:

  • it eliminates the reference_timestamp == i64::MIN condition which doesn't look good IMO
  • it avoids breaking changes, as it will be backward compatible

With that in mind, the python wrapper should call either the existing API or the new one, depending on wether or not a reference_timestamp was provided.

What do you think?

@niedakh
Copy link
Author

niedakh commented Aug 6, 2018

@adrienball I agree, this makes a lot of sense, I should be able to update the PR this week

@adrienball
Copy link
Collaborator

BTW, we bumped the version of rustling-ontology in this PR, and now Moment, Local and TimeZone types are re-exported by rustling-ontology so you should be able to remove the chrono and rustling-ontology-moment dependencies.

Also, the ResolverContext struct now has a new builder:

struct ResolverContext {
    pub fn from_nsecs(nsecs: i64) -> ResolverContext;
}

which you can use directly.

@adrienball adrienball closed this Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants