diff --git a/core/data/en/colors.json b/core/data/en/colors.json index bd2c3d99e..e3d50de77 100644 --- a/core/data/en/colors.json +++ b/core/data/en/colors.json @@ -3,13 +3,18 @@ "red": { "synonyms": ["red"], "data": { - "usage": "The red color is often used for danger" + "usage": [ + "The red color is often used for danger" + ] } }, "blue": { "synonyms": ["blue"], "data": { - "usage": "The blue color is often used for that..." + "usage": [ + "The blue color is often used for that...", + "222 The blue color is often used for that..." + ] } } } diff --git a/scripts/train.js b/scripts/train.js index 72dc35105..45c89c9a2 100644 --- a/scripts/train.js +++ b/scripts/train.js @@ -8,6 +8,7 @@ import path from 'path' import log from '@/helpers/log' import lang from '@/helpers/lang' import domain from '@/helpers/domain' +import string from '@/helpers/string' dotenv.config() @@ -58,7 +59,8 @@ export default () => new Promise(async (resolve, reject) => { const nluFilePath = path.join(currentSkill.path, 'nlu', `${lang}.json`) if (fs.existsSync(nluFilePath)) { - const { actions, entities } = JSON.parse(fs.readFileSync(nluFilePath, 'utf8')) + const { actions, entities, variables } = JSON.parse(fs.readFileSync(nluFilePath, 'utf8')) + // const { actions, entities } = loadNluFile(nluFilePath) const actionsKeys = Object.keys(actions) for (let k = 0; k < actionsKeys.length; k += 1) { @@ -74,7 +76,25 @@ export default () => new Promise(async (resolve, reject) => { // Train NLG if the skill has a dialog type if (currentSkill.type === 'dialog') { + const variablesObj = { } + + // Dynamic variables binding if any variable is declared + if (variables) { + const variableKeys = Object.keys(variables) + + for (let l = 0; l < variableKeys.length; l += 1) { + const key = variableKeys[l] + + variablesObj[`%${key}%`] = variables[variableKeys[l]] + } + } + for (let l = 0; l < answers?.length; l += 1) { + const variableKeys = Object.keys(variablesObj) + if (variableKeys.length > 0) { + answers[l] = string.pnr(answers[l], variablesObj) + } + nlp.addAnswer(lang, `${skillName}.${actionName}`, answers[l]) } }