diff --git a/scripts/train.js b/scripts/train.js index f597684f..d9d18463 100644 --- a/scripts/train.js +++ b/scripts/train.js @@ -111,8 +111,9 @@ export default () => new Promise(async (resolve, reject) => { * > Well, the red color... * - Do you like this color? * > Red is cool, but I prefer... - * 11. "Add potatoes to my shopping list" ... "Actually remove it" - * Need to see in current context and loop through classifications intent. + * 11. [OK] "Add potatoes to my shopping list" ... "Actually remove it" + * The entities are already persistent in context. + * Just need to check in current context and loop through classifications intent. * If the skill is found, then use that intent. So an intent should not always be * the one with the highest confidence * 12. Modify skills as per new code (skill params became dictionary [OK], etc.) diff --git a/server/src/core/nlu.js b/server/src/core/nlu.js index d925cefb..e01fd147 100644 --- a/server/src/core/nlu.js +++ b/server/src/core/nlu.js @@ -139,10 +139,33 @@ class Nlu { } const result = await this.nlp.process(utterance) - // console.log('result', result) + console.log('result', result) const { - locale, domain, intent, score, answers + locale, answers, classifications } = result + let { score, intent, domain } = result + + /** + * If a context is active, then use the appropriate classification based on score probability. + * E.g. 1. Create my shopping list; 2. Actually delete it. + * If there are several "delete it" across skills, Leon needs to make use of + * the current context ({domain}.{skill}) to define the most accurate classification + */ + if (this.conv.hasActiveContext()) { + classifications.forEach(({ intent: newIntent, score: newScore }) => { + if (newScore > 0.6) { + const [skillName] = newIntent.split('.') + const newDomain = this.nlp.getIntentDomain(locale, newIntent) + const contextName = `${newDomain}.${skillName}` + if (this.conv.activeContext.name === contextName) { + score = newScore + intent = newIntent + domain = newDomain + } + } + }) + } + const [skillName, actionName] = intent.split('.') this.nluResultObj = { ...this.nluResultObj, @@ -370,11 +393,10 @@ class Nlu { * 5.3 [OK] Need to handle the case if a context is filled in one shot * e.g. I wanna play with 2 players and louis.grenard@gmail.com * Need to refactor now (nluResultObj method to build it, etc.) - * 6. What's next once the next action has been executed? - * 7. Handle a "loop" feature from action (guess the number) + * 6. Handle a "loop" feature from action (guess the number) * No need "loop" in the NLU skill config. Just add option in util output - * 8. Split this process() method into several ones + clean nlu.js and brain.js - * 9. Add logs in terminal about context switching, active context, etc. + * 7. Split this process() method into several ones + clean nlu.js and brain.js + * 8. Add logs in terminal about context switching, active context, etc. */ this.nluResultObj = {