Skip to content

Commit 54d9423

Browse files
committed
fix(core): gestion des synonymes avec des mots composés
1 parent 56e682f commit 54d9423

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

app/js/core/interactions/helpers/findBestResponse/computeSimilarityScore.mjs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { normalizeText } from "../../../../utils/nlp.mjs";
22
import { computeResponseScore } from "./computeResponseScore.mjs";
33

44
export function computeSimilarityScore(chatbot, userInputRaw, yaml) {
5-
let userInput = normalizeText(userInputRaw);
5+
const normalizedUserInput = normalizeText(userInputRaw);
6+
let userInput = normalizedUserInput;
67

78
let bestMatch = null;
89
let bestMatchScore = 0;
@@ -47,6 +48,23 @@ export function computeSimilarityScore(chatbot, userInputRaw, yaml) {
4748
" " + synonymsArray.filter((syn) => syn !== userWord).join(" ");
4849
// On passe au mot suivant si on a trouvé une correspondance
4950
break;
51+
} else {
52+
// si la liste de synonymes contient des mots composés
53+
const multiWordSynonyms = synonymsArray.filter(
54+
(syn) => syn.trim().split(" ").length > 1,
55+
);
56+
for (const multiWordSynonym of multiWordSynonyms) {
57+
if (normalizedUserInput.includes(multiWordSynonym)) {
58+
// On a trouvé une correspondance, on ajoute tous les synonymes au message de l'utilisateur
59+
userInput +=
60+
" " +
61+
synonymsArray
62+
.filter((syn) => syn !== multiWordSynonym)
63+
.join(" ");
64+
// On passe au mot suivant si on a trouvé une correspondance
65+
break;
66+
}
67+
}
5068
}
5169
}
5270
}

app/script.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/script.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)