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

Raise an error when using unknown intents in intents filter #788

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 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.

## [Unreleased]
### Fixed
- Raise an error when using unknown intents in intents filter [#788](https://github.com/snipsco/snips-nlu/pull/788)

## [0.19.5]
### Added
- Advanced inference logging in the `CRFSlotFiller` [#776](https://github.com/snipsco/snips-nlu/pull/776)
Expand Down
5 changes: 5 additions & 0 deletions snips_nlu/nlu_engine/nlu_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ def parse(self, text, intents=None, top_n=None):
elif isinstance(intents, list):
intents = set(intents)

if intents is not None:
for intent in intents:
if intent not in self.dataset_metadata["slot_name_mappings"]:
raise IntentNotFoundError(intent)

if top_n is None:
none_proba = 0.0
for parser in self.intent_parsers:
Expand Down
33 changes: 33 additions & 0 deletions snips_nlu/tests/test_nlu_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,39 @@ class SecondIntentParser(MockIntentParser):
with self.assertRaises(IntentNotFoundError):
nlu_engine.get_slots("Hello John", "greeting3")

def test_parse_should_raise_with_unknown_intent_in_filter(self):
# Given
dataset_stream = io.StringIO("""
---
type: intent
name: greeting1
utterances:
- Hello [name1](John)

---
type: intent
name: goodbye
utterances:
- Goodbye [name](Eric)""")
dataset = Dataset.from_yaml_files("en", [dataset_stream]).json

# pylint:disable=unused-variable
@IntentParser.register("my_intent_parser", True)
class FirstIntentParser(MockIntentParser):
pass

# pylint:enable=unused-variable

config = NLUEngineConfig(["my_intent_parser"])
nlu_engine = SnipsNLUEngine(config).fit(dataset)

# When / Then
with self.assertRaises(IntentNotFoundError):
nlu_engine.parse("Hello John", intents="greeting3")

with self.assertRaises(IntentNotFoundError):
nlu_engine.parse("Hello John", intents=["greeting3"])

def test_should_use_parsers_sequentially(self):
# Given
dataset_stream = io.StringIO("""
Expand Down