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

Issues/114 #128

Merged
merged 4 commits into from
Apr 26, 2021
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
19 changes: 10 additions & 9 deletions adapt/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,14 @@ 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): 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
Expand All @@ -152,7 +154,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, []
Expand All @@ -161,8 +163,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)
Expand All @@ -178,18 +179,18 @@ 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)
forslund marked this conversation as resolved.
Show resolved Hide resolved
if not optional_tag or attribute_name in result:
continue
result[attribute_name] = canonical_form
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) * 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
Expand Down
11 changes: 11 additions & 0 deletions test/IntentEngineTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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