From b3fa9e99b0a5571f1fe1ac560e13348a8a1738d0 Mon Sep 17 00:00:00 2001 From: Sean Fitzgerald Date: Sun, 25 Apr 2021 20:17:30 -0700 Subject: [PATCH 1/4] Addresses issues/114 --- adapt/intent.py | 15 +++++++-------- test/IntentEngineTest.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/adapt/intent.py b/adapt/intent.py index ca0f934..9237285 100644 --- a/adapt/intent.py +++ b/adapt/intent.py @@ -134,12 +134,12 @@ def validate(self, tags, confidence): intent, tags = self.validate_with_tags(tags, confidence) return intent - def validate_with_tags(self, tags, confidence): + def validate_with_tags(self, tags, parse_weight): """Validate whether tags has required entites for this intent to fire Args: tags(list): Tags and Entities used for validation - confidence(float): ? + parse_weight(float): ? Returns: intent, tags: Returns intent and tags used by the intent on @@ -152,7 +152,7 @@ def validate_with_tags(self, tags, confidence): used_tags = [] for require_type, attribute_name in self.requires: - required_tag, canonical_form, confidence = find_first_tag(local_tags, require_type) + required_tag, canonical_form, tag_confidence = find_first_tag(local_tags, require_type) if not required_tag: result['confidence'] = 0.0 return result, [] @@ -161,8 +161,7 @@ def validate_with_tags(self, tags, confidence): if required_tag in local_tags: local_tags.remove(required_tag) used_tags.append(required_tag) - # TODO: use confidence based on edit distance and context - intent_confidence += confidence + intent_confidence += tag_confidence if len(self.at_least_one) > 0: best_resolution = resolve_one_of(tags, self.at_least_one) @@ -178,7 +177,7 @@ def validate_with_tags(self, tags, confidence): local_tags.remove(best_resolution) for optional_type, attribute_name in self.optional: - optional_tag, canonical_form, conf = find_first_tag(local_tags, optional_type) + optional_tag, canonical_form, tag_confidence = find_first_tag(local_tags, optional_type) if not optional_tag or attribute_name in result: continue result[attribute_name] = canonical_form @@ -187,9 +186,9 @@ def validate_with_tags(self, tags, confidence): used_tags.append(optional_tag) intent_confidence += 1.0 - total_confidence = intent_confidence / len(tags) * confidence + total_confidence = intent_confidence / len(tags) * parse_weight if tags else 0.0 - target_client, canonical_form, confidence = find_first_tag(local_tags, CLIENT_ENTITY_NAME) + target_client, canonical_form, parse_weight = find_first_tag(local_tags, CLIENT_ENTITY_NAME) result['target'] = target_client.get('key') if target_client else None result['confidence'] = total_confidence diff --git a/test/IntentEngineTest.py b/test/IntentEngineTest.py index be7ca24..1772bc1 100644 --- a/test/IntentEngineTest.py +++ b/test/IntentEngineTest.py @@ -165,3 +165,14 @@ def matcher(regexp): self.engine.drop_regex_entity(match_func=matcher) assert len(self.engine._regex_strings) == 2 assert len(self.engine.regular_expressions_entities) == 2 + def testEmptyTags(self): + # Validates https://github.com/MycroftAI/adapt/issues/114 + engine = IntentDeterminationEngine() + engine.register_entity("Kevin", + "who") # same problem if several entities + builder = IntentBuilder("Buddies") + builder.optionally("who") # same problem if several entity types + engine.register_intent_parser(builder.build()) + + intents = [i for i in engine.determine_intent("Julien is a friend")] + assert len(intents) == 0 From 75116ebc0de6994bb993dd1d758f294683db1263 Mon Sep 17 00:00:00 2001 From: Sean Fitzgerald Date: Sun, 25 Apr 2021 20:27:43 -0700 Subject: [PATCH 2/4] Slightly clearer conditional --- adapt/intent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapt/intent.py b/adapt/intent.py index 9237285..fbb77d0 100644 --- a/adapt/intent.py +++ b/adapt/intent.py @@ -186,7 +186,7 @@ def validate_with_tags(self, tags, parse_weight): used_tags.append(optional_tag) intent_confidence += 1.0 - total_confidence = intent_confidence / len(tags) * parse_weight if tags else 0.0 + total_confidence = (intent_confidence / len(tags) * parse_weight) if tags else 0.0 target_client, canonical_form, parse_weight = find_first_tag(local_tags, CLIENT_ENTITY_NAME) From e23c67b188e867da9f673d6303115cbb46b9f74a Mon Sep 17 00:00:00 2001 From: Sean Fitzgerald Date: Sun, 25 Apr 2021 21:03:10 -0700 Subject: [PATCH 3/4] Update comments --- adapt/intent.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adapt/intent.py b/adapt/intent.py index fbb77d0..5001b2b 100644 --- a/adapt/intent.py +++ b/adapt/intent.py @@ -139,7 +139,9 @@ def validate_with_tags(self, tags, parse_weight): Args: tags(list): Tags and Entities used for validation - parse_weight(float): ? + parse_weight(float): The weight associate to the parse result, + as indicated by the parser. This is influenced by a parser + that uses edit distance or context. Returns: intent, tags: Returns intent and tags used by the intent on From 6745ed6f289dc959ed999babe5177ae4ff232caf Mon Sep 17 00:00:00 2001 From: Sean Fitzgerald Date: Mon, 26 Apr 2021 07:16:50 -0700 Subject: [PATCH 4/4] Use tag_confidence for optional tags --- adapt/intent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adapt/intent.py b/adapt/intent.py index 5001b2b..fae865b 100644 --- a/adapt/intent.py +++ b/adapt/intent.py @@ -186,7 +186,7 @@ def validate_with_tags(self, tags, parse_weight): if optional_tag in local_tags: local_tags.remove(optional_tag) used_tags.append(optional_tag) - intent_confidence += 1.0 + intent_confidence += tag_confidence total_confidence = (intent_confidence / len(tags) * parse_weight) if tags else 0.0