Skip to content
This repository has been archived by the owner on Feb 26, 2021. It is now read-only.

Commit

Permalink
Fix #338, make intent parsing prefer small-slot matches
Browse files Browse the repository at this point in the history
The idea is just that the more characters get matched by the static portion (not slot portion) of the intent, the better a match it is
  • Loading branch information
ianb committed Sep 27, 2019
1 parent b16bd40 commit 80b9dcd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion extension/background/intentParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,24 @@ this.intentParser = (function() {
text = text.replace(/\s\s+/g, " ");
text = text.toLowerCase();
text = text.replace(/[^a-z0-9 ']/gi, "");
let bestMatch;
let bestChars;
for (const name of INTENT_NAMES) {
const matcher = INTENTS[name].matcher;
const match = matcher.match(text);
if (match) {
match.name = name;
match.fallback = false;
return match;
const slotChars = Object.values(match.slots).join("").length;
if (bestMatch === undefined || bestChars > slotChars) {
bestMatch = match;
bestChars = slotChars;
}
}
}
if (bestMatch) {
return bestMatch;
}
if (disableFallback) {
return null;
}
Expand Down

0 comments on commit 80b9dcd

Please sign in to comment.