Skip to content

Commit

Permalink
Release 0.67.1 (#155)
Browse files Browse the repository at this point in the history
* Add default deserialization for alternative intents and slot values when missing

* Add test
  • Loading branch information
adrienball authored Sep 2, 2019
1 parent dbf0903 commit c179fc0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 44 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [0.67.1] - 2019-09-02
### Fixed
- Add default deserialization for alternative intents and slot values when missing [#155](https://github.com/snipsco/snips-nlu-ontology/pull/155)

## [0.67.0] - 2019-08-28
### Added
- Add an `alternatives` attribute, containing less likely alternatives, to ([#153](https://github.com/snipsco/snips-nlu-ontology/pull/153)):
Expand Down Expand Up @@ -201,6 +205,7 @@ All notable changes to this project will be documented in this file.
### Changed
- Updated Rustling ontology to `0.16.4`

[0.67.1]: https://github.com/snipsco/snips-nlu-ontology/compare/0.67.0...0.67.1
[0.67.0]: https://github.com/snipsco/snips-nlu-ontology/compare/0.66.0...0.67.0
[0.66.0]: https://github.com/snipsco/snips-nlu-ontology/compare/0.65.0...0.66.0
[0.65.0]: https://github.com/snipsco/snips-nlu-ontology/compare/0.64.8...0.65.0
Expand Down
93 changes: 49 additions & 44 deletions src/ontology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct IntentParserResult {
pub input: String,
pub intent: IntentClassifierResult,
pub slots: Vec<Slot>,
#[serde(default)]
pub alternatives: Vec<IntentParserAlternative>,
}

Expand All @@ -26,6 +27,7 @@ pub struct IntentClassifierResult {
pub struct Slot {
pub raw_value: String,
pub value: SlotValue,
#[serde(default)]
pub alternatives: Vec<SlotValue>,
pub range: Range<usize>,
pub entity: String,
Expand Down Expand Up @@ -188,51 +190,54 @@ mod tests {
use super::*;

#[test]
fn test_custom_slot() {
let slot = Slot {
raw_value: "value".into(),
value: SlotValue::Custom("value".into()),
fn test_deserializing_with_default_alternatives() {
// Given
let intent_parser_result_json = r#"
{
"input": "foo bar baz",
"intent": {
"intentName": "FooBar",
"confidenceScore": 0.42
},
"slots": [
{
"rawValue": "baz",
"value": {
"kind": "Custom",
"value": "baz"
},
"range": {
"start": 8,
"end": 11
},
"entity": "foo",
"slotName": "foo"
}
]
}
"#;

// When
let deserialized = serde_json::from_str(intent_parser_result_json).unwrap();

// Then
let expected_result = IntentParserResult {
input: "foo bar baz".to_string(),
intent: IntentClassifierResult {
intent_name: Some("FooBar".to_string()),
confidence_score: 0.42,
},
slots: vec![Slot {
value: SlotValue::Custom("baz".into()),
raw_value: "baz".to_string(),
range: 8..11,
entity: "foo".to_string(),
slot_name: "foo".to_string(),
alternatives: vec![],
confidence_score: None,
}],
alternatives: vec![],
range: 0..5,
entity: "toto".into(),
slot_name: "toto".into(),
confidence_score: None,
};
assert!(serde_json::to_string(&slot).is_ok());
assert!(serde_json::from_str::<Slot>(&serde_json::to_string(&slot).unwrap()).is_ok());
}

#[test]
fn test_builtin_slot_1() {
let slot = Slot {
raw_value: "fifth".into(),
value: SlotValue::Ordinal(OrdinalValue { value: 5 }),
alternatives: vec![],
range: 0..5,
entity: "toto".into(),
slot_name: "toto".into(),
confidence_score: Some(0.8),
};
assert!(serde_json::to_string(&slot).is_ok());
assert!(serde_json::from_str::<Slot>(&serde_json::to_string(&slot).unwrap()).is_ok());
}

#[test]
fn test_builtin_slot_2() {
let slot = Slot {
raw_value: "some_value".into(),
value: SlotValue::InstantTime(InstantTimeValue {
value: "some_value".into(),
grain: Grain::Year,
precision: Precision::Exact,
}),
alternatives: vec![],
range: 0..10,
entity: "toto".into(),
slot_name: "toto".into(),
confidence_score: None,
};
assert!(serde_json::to_string(&slot).is_ok());
assert!(serde_json::from_str::<Slot>(&serde_json::to_string(&slot).unwrap()).is_ok());
assert_eq!(expected_result, deserialized);
}
}

0 comments on commit c179fc0

Please sign in to comment.