diff --git a/hassil/VERSION b/hassil/VERSION index 2165f8f..e010258 100644 --- a/hassil/VERSION +++ b/hassil/VERSION @@ -1 +1 @@ -2.0.4 +2.0.5 diff --git a/hassil/string_matcher.py b/hassil/string_matcher.py index 746b6c0..06becd5 100644 --- a/hassil/string_matcher.py +++ b/hassil/string_matcher.py @@ -388,8 +388,8 @@ def match_expression( entities=context.entities, intent_context=context.intent_context, is_start_of_word=True, - # unmatched_entities=context.unmatched_entities, - text_chunks_matched=context.text_chunks_matched, + text_chunks_matched=context.text_chunks_matched + + len(chunk.text.strip()), intent_sentence=context.intent_sentence, intent_data=context.intent_data, # diff --git a/tests/test_recognize.py b/tests/test_recognize.py index 25f9ab8..a2d36ba 100644 --- a/tests/test_recognize.py +++ b/tests/test_recognize.py @@ -978,6 +978,38 @@ def test_unmatched_entities_cant_skip_words() -> None: assert len(results) == 0 +def test_unmatched_entities_text_chunks_matched() -> None: + yaml_text = """ + language: "en" + intents: + Test: + data: + - sentences: + - "[turn] on {name}" + - "[turn] on {name} light" + lists: + name: + values: + - test + """ + + with io.StringIO(yaml_text) as test_file: + intents = Intents.from_yaml(test_file) + + sentence = "turn on unknown light" + + results = list(recognize_all(sentence, intents, allow_unmatched_entities=True)) + assert len(results) == 2 + + # '[turn] on {name} light' should have more literal text matched + result_1, result_2 = results + assert result_1.intent_sentence is not None + if result_1.intent_sentence.text == "[turn] on {name}": + assert result_1.text_chunks_matched < result_2.text_chunks_matched + else: + assert result_2.text_chunks_matched < result_1.text_chunks_matched + + def test_wildcard() -> None: """Test wildcard slot lists/entities.""" yaml_text = """