-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conversation
note that my Cargo.ml repository url changes should be reverted before merging |
There was a problem hiding this 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" } |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
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)) | |||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) | ||
); |
There was a problem hiding this comment.
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());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@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? |
Hey @niedakh ,
This has two advantages:
With that in mind, the python wrapper should call either the existing API or the new one, depending on wether or not a What do you think? |
@adrienball I agree, this makes a lot of sense, I should be able to update the PR this week |
BTW, we bumped the version of Also, the
which you can use directly. |
This PR adds an additional parameter to provide a reference timestamp for datetimes detected by rustling.