Skip to content

Commit 158c7c7

Browse files
committed
matching: simplify matching logic and add more edgecase-tests
1 parent 204ce4d commit 158c7c7

3 files changed

Lines changed: 485 additions & 224 deletions

File tree

custom_components/closest_intent/conversation.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def _best_extractable_sibling(
718718
"""Highest-scoring same-intent slot-bearing sibling whose slots extract."""
719719
scored = sorted(
720720
(
721-
(score(user_text, c.text, resolver), c)
721+
(score(user_text, c.text, resolver, slot_names=c.slot_names), c)
722722
for c in candidates
723723
if c is not skip and c.intent == skip.intent and c.has_slots
724724
),
@@ -746,13 +746,19 @@ def _self_check(
746746
if not user_candidates:
747747
return []
748748
combined = user_candidates + builtin_candidates
749+
sc_resolver = Resolver(
750+
expansion_rules=resolver.expansion_rules,
751+
slot_values={},
752+
match_threshold=resolver.match_threshold,
753+
slot_resolution_threshold=resolver.slot_resolution_threshold,
754+
)
749755
clashes: list[dict] = []
750756
for c in user_candidates:
751757
perfect = _materialise_candidate_input(c)
752758
if not perfect:
753759
continue
754760
try:
755-
detail = self._match(perfect, resolver, combined)
761+
detail = self._match(perfect, sc_resolver, combined)
756762
except Exception: # pragma: no cover
757763
_LOGGER.exception("self_check: match raised for %r", perfect)
758764
continue
@@ -872,7 +878,7 @@ async def parse_sentence(
872878
if debug_top_candidates:
873879
scored_for_debug = sorted(
874880
(
875-
(c, score(sentence, c.text, resolver))
881+
(c, score(sentence, c.text, resolver, slot_names=c.slot_names))
876882
for c in (user_candidates + builtin_candidates)
877883
),
878884
key=lambda cs: -cs[1],

0 commit comments

Comments
 (0)