Skip to content

Commit afbf6c5

Browse files
authored
error_handling/very_large_utterances (#392)
if we get a very large utterance (over 50 words) we are almost certain any intent match is wrong these utterances are better handled by a fallback skill, skip adapt/padatious matching entirely
1 parent 98e8b46 commit afbf6c5

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

ovos_core/intent_services/adapt_service.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(self, config=None):
5555
for lang in langs}
5656

5757
self.lock = Lock()
58+
self.max_words = 50 # if an utterance contains more words than this, don't attempt to match
5859

5960
@property
6061
def context_keywords(self):
@@ -143,6 +144,12 @@ def match_intent(self, utterances, lang=None, message=None):
143144
"""
144145
# we call flatten in case someone is sending the old style list of tuples
145146
utterances = flatten_list(utterances)
147+
148+
utterances = [u for u in utterances if len(u.split()) < self.max_words]
149+
if not utterances:
150+
LOG.error(f"utterance exceeds max size of {self.max_words} words, skipping adapt match")
151+
return None
152+
146153
lang = lang or self.lang
147154
if lang not in self.engines:
148155
return None

ovos_core/intent_services/padacioso_service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__(self, bus, config):
7373

7474
self.registered_intents = []
7575
self.registered_entities = []
76+
self.max_words = 50 # if an utterance contains more words than this, don't attempt to match
7677

7778
def _match_level(self, utterances, limit, lang=None):
7879
"""Match intent and make sure a certain level of confidence is reached.
@@ -217,6 +218,10 @@ def calc_intent(self, utterances: List[str], lang: str = None) -> Optional[Padac
217218
"""
218219
if isinstance(utterances, str):
219220
utterances = [utterances] # backwards compat when arg was a single string
221+
utterances = [u for u in utterances if len(u.split()) < self.max_words]
222+
if not utterances:
223+
LOG.error(f"utterance exceeds max size of {self.max_words} words, skipping padacioso match")
224+
return None
220225
lang = lang or self.lang
221226
lang = lang.lower()
222227
if lang in self.containers:

ovos_core/intent_services/padatious_service.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def __init__(self, bus, config):
124124

125125
self.registered_intents = []
126126
self.registered_entities = []
127+
self.max_words = 50 # if an utterance contains more words than this, don't attempt to match
127128

128129
def train(self, message=None):
129130
"""Perform padatious training.
@@ -259,6 +260,11 @@ def calc_intent(self, utterances: List[str], lang: str = None) -> Optional[Padat
259260
"""
260261
if isinstance(utterances, str):
261262
utterances = [utterances] # backwards compat when arg was a single string
263+
utterances = [u for u in utterances if len(u.split()) < self.max_words]
264+
if not utterances:
265+
LOG.error(f"utterance exceeds max size of {self.max_words} words, skipping padatious match")
266+
return None
267+
262268
lang = lang or self.lang
263269
lang = lang.lower()
264270
if lang in self.containers:

0 commit comments

Comments
 (0)