Skip to content

Commit

Permalink
Merge pull request #124 from snipsco/fix/parser-group-issues
Browse files Browse the repository at this point in the history
Release 0.61.1 - Fix bug with regex patterns containing duplicated slot names
  • Loading branch information
adrienball authored Mar 1, 2019
2 parents 3f5a57a + 1a12a6e commit c8025bc
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 25 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.64.1] - 2019-03-01
### Fixed
- Fix bug with regex patterns containing duplicated slot names

## [0.64.0] - 2019-02-28
### Changed
- Bumped `snips-nlu-ontology` to 0.64.4
Expand Down Expand Up @@ -174,6 +178,7 @@ being statically hardcoded, reducing the binary size by 31Mb.
- Improve support for japanese
- Rename python package to `snips_nlu_rust`

[0.64.1]: https://github.com/snipsco/snips-nlu-rs/compare/0.64.0...0.64.1
[0.64.0]: https://github.com/snipsco/snips-nlu-rs/compare/0.63.1...0.64.0
[0.63.1]: https://github.com/snipsco/snips-nlu-rs/compare/0.63.0...0.63.1
[0.63.0]: https://github.com/snipsco/snips-nlu-rs/compare/0.62.0...0.63.0
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "snips-nlu-lib"
version = "0.64.0"
version = "0.64.1"
authors = [
"Adrien Ball <[email protected]>",
"Clement Doumouro <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "snips-nlu-ffi"
version = "0.64.0"
version = "0.64.1"
edition = "2018"
authors = [
"Adrien Ball <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion platforms/c/libsnips_nlu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdlib.h>
#include <stdbool.h>

#define SNIPS_NLU_VERSION "0.64.0"
#define SNIPS_NLU_VERSION "0.64.1"

/*
* Enum representing the grain of a resolved date related value
Expand Down
2 changes: 1 addition & 1 deletion platforms/kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {

apply plugin: 'kotlin'

version = "0.64.0"
version = "0.64.1"
group = "ai.snips"

repositories {
Expand Down
4 changes: 2 additions & 2 deletions platforms/python/ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "snips-nlu-python-ffi"
version = "0.64.0"
version = "0.64.1"
authors = ["Adrien Ball <[email protected]>"]
edition = "2018"

Expand All @@ -11,4 +11,4 @@ crate-type = ["cdylib"]
[dependencies]
libc = "0.2"
ffi-utils = { git = "https://github.com/snipsco/snips-utils-rs", rev = "4292ad9" }
snips-nlu-ffi = { git = "https://github.com/snipsco/snips-nlu-rs", tag = "0.64.0" }
snips-nlu-ffi = { git = "https://github.com/snipsco/snips-nlu-rs", tag = "0.64.1" }
2 changes: 1 addition & 1 deletion platforms/python/snips_nlu_rust/__version__
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.64.0
0.64.1
2 changes: 1 addition & 1 deletion platforms/swift/SnipsNlu/Dependencies/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

set -e

VERSION="0.64.0"
VERSION="0.64.1"
SYSTEM=$(echo $1 | tr '[:upper:]' '[:lower:]')
LIBRARY_NAME=libsnips_nlu_ffi
LIBRARY_NAME_A=${LIBRARY_NAME}.a
Expand Down
15 changes: 15 additions & 0 deletions post_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

VERSION=$1

if [[ -z "$VERSION" ]]
then
echo "Usage: $0 <version>"
exit 1
fi

set -ex

./update_version.sh ${VERSION}

git commit . -m "Set post-release version to $VERSION"
99 changes: 82 additions & 17 deletions src/intent_parser/deterministic_intent_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ impl DeterministicIntentParser {
}
})
.map(|(a_match, group_name)| {
let group_name = group_name.split('_').collect::<Vec<&str>>()[0];
let slot_name = self.group_names_to_slot_names[group_name].to_string();
let entity = self.slot_names_to_entities[intent][&slot_name].to_string();
let byte_range = a_match.start()..a_match.end();
Expand Down Expand Up @@ -368,29 +369,33 @@ mod tests {
language_code: "en".to_string(),
patterns: hashmap![
"dummy_intent_1".to_string() => vec![
r"^\s*This\s*is\s*a\s*(?P<group_1>%DUMMY_ENTITY_1%)\s*query\s*with\s*another\s*(?P<group_2>%DUMMY_ENTITY_2%)\s*$".to_string(),
r"^\s*(?P<group_5>%DUMMY_ENTITY_1%)\s*$".to_string(),
r"^\s*This\s*is\s*another\s*(?P<group_3>%DUMMY_ENTITY_2%)\s*query\s*$".to_string(),
r"^\s*This\s*is\s*another\s*über\s*(?P<group_3>%DUMMY_ENTITY_2%)\s*query.\s*$".to_string(),
r"^\s*This\s*is\s*another\s*(?P<group_4>%DUMMY_ENTITY_2%)?\s*$*".to_string(),
r"^\s*This\s*is\s*a\s*(?P<group1>%DUMMY_ENTITY_1%)\s*query\s*with\s*another\s*(?P<group2>%DUMMY_ENTITY_2%)\s*$".to_string(),
r"^\s*(?P<group5>%DUMMY_ENTITY_1%)\s*$".to_string(),
r"^\s*This\s*is\s*another\s*(?P<group3>%DUMMY_ENTITY_2%)\s*query\s*$".to_string(),
r"^\s*This\s*is\s*another\s*über\s*(?P<group3>%DUMMY_ENTITY_2%)\s*query.\s*$".to_string(),
r"^\s*This\s*is\s*another\s*(?P<group4>%DUMMY_ENTITY_2%)?\s*$*".to_string(),
],
"dummy_intent_2".to_string() => vec![
r"^\s*This\s*is\s*a\s*(?P<group_0>%DUMMY_ENTITY_1%)\s*query\s*from\s*another\s*intent\s*$".to_string()
r"^\s*This\s*is\s*a\s*(?P<group0>%DUMMY_ENTITY_1%)\s*query\s*from\s*another\s*intent\s*$".to_string()
],
"dummy_intent_3".to_string() => vec![
r"^\s*Send\s*(?P<group_6>%SNIPSAMOUNTOFMONEY%)\s*to\s*john\s*$".to_string(),
r"^\s*Send\s*(?P<group_6>%SNIPSAMOUNTOFMONEY%)\s*to\s*john\s*at\s*(?P<group_7>%DUMMY_ENTITY_2%)\s*$".to_string()
r"^\s*Send\s*(?P<group6>%SNIPSAMOUNTOFMONEY%)\s*to\s*john\s*$".to_string(),
r"^\s*Send\s*(?P<group6>%SNIPSAMOUNTOFMONEY%)\s*to\s*john\s*at\s*(?P<group7>%DUMMY_ENTITY_2%)\s*$".to_string()
],
"dummy_intent_4".to_string() => vec![
r"^\s*what\s*is\s*(?P<group8>%SNIPSNUMBER%)\s*plus\s*(?P<group8_2>%SNIPSNUMBER%)\s*$".to_string()
],
],
group_names_to_slot_names: hashmap![
"group_0".to_string() => "dummy_slot_name".to_string(),
"group_1".to_string() => "dummy_slot_name".to_string(),
"group_2".to_string() => "dummy_slot_name2".to_string(),
"group_3".to_string() => "dummy_slot_name2".to_string(),
"group_4".to_string() => "dummy_slot_name3".to_string(),
"group_5".to_string() => "dummy_slot_name".to_string(),
"group_6".to_string() => "dummy_slot_name4".to_string(),
"group_7".to_string() => "dummy_slot_name2".to_string(),
"group0".to_string() => "dummy_slot_name".to_string(),
"group1".to_string() => "dummy_slot_name".to_string(),
"group2".to_string() => "dummy_slot_name2".to_string(),
"group3".to_string() => "dummy_slot_name2".to_string(),
"group4".to_string() => "dummy_slot_name3".to_string(),
"group5".to_string() => "dummy_slot_name".to_string(),
"group6".to_string() => "dummy_slot_name4".to_string(),
"group7".to_string() => "dummy_slot_name2".to_string(),
"group8".to_string() => "dummy_slot_name5".to_string(),
],
slot_names_to_entities: hashmap![
"dummy_intent_1".to_string() => hashmap![
Expand All @@ -405,6 +410,9 @@ mod tests {
"dummy_slot_name2".to_string() => "dummy_entity_2".to_string(),
"dummy_slot_name4".to_string() => "snips/amountOfMoney".to_string(),
],
"dummy_intent_4".to_string() => hashmap![
"dummy_slot_name5".to_string() => "snips/number".to_string(),
],
],
config: DeterministicParserConfig {
ignore_stop_words: true,
Expand Down Expand Up @@ -560,7 +568,7 @@ mod tests {
intent_name: Some("dummy_intent_1".to_string()),
confidence_score: 1.0,
};
assert_eq!(4, intents.len());
assert_eq!(5, intents.len());
assert_eq!(&first_intent, &intents[0]);
assert_eq!(0.0, intents[1].confidence_score);
assert_eq!(0.0, intents[2].confidence_score);
Expand Down Expand Up @@ -603,6 +611,63 @@ mod tests {
assert_eq!(intent, expected_intent);
}

#[test]
fn test_parse_utterance_with_duplicated_slot_name() {
// Given
let text = "what is one plus one";
let mocked_builtin_entity_parser = MockedBuiltinEntityParser::from_iter(vec![(
text.to_string(),
vec![
BuiltinEntity {
value: "one".to_string(),
range: 8..11,
entity: SlotValue::Number(NumberValue { value: 1. }),
entity_kind: BuiltinEntityKind::Number,
},
BuiltinEntity {
value: "one".to_string(),
range: 17..20,
entity: SlotValue::Number(NumberValue { value: 1. }),
entity_kind: BuiltinEntityKind::Number,
},
],
)]);
let shared_resources = SharedResourcesBuilder::default()
.builtin_entity_parser(mocked_builtin_entity_parser)
.build();
let parser =
DeterministicIntentParser::new(test_configuration(), Arc::new(shared_resources))
.unwrap();

// When
let parsing_result = parser.parse(text, None).unwrap();
let intent = parsing_result.intent;
let slots = parsing_result.slots;

// Then
let expected_intent = IntentClassifierResult {
intent_name: Some("dummy_intent_4".to_string()),
confidence_score: 1.0,
};
let expected_slots = vec![
InternalSlot {
value: "one".to_string(),
char_range: 8..11,
entity: "snips/number".to_string(),
slot_name: "dummy_slot_name5".to_string(),
},
InternalSlot {
value: "one".to_string(),
char_range: 17..20,
entity: "snips/number".to_string(),
slot_name: "dummy_slot_name5".to_string(),
},
];

assert_eq!(expected_intent, intent);
assert_eq!(expected_slots, slots);
}

#[test]
fn test_parse_intent_by_ignoring_stop_words() {
// Given
Expand Down

0 comments on commit c8025bc

Please sign in to comment.