From e4d3904ceeb2a3ee2c0187a1817331fac916e1a7 Mon Sep 17 00:00:00 2001 From: louistiti Date: Mon, 14 Feb 2022 16:48:03 +0800 Subject: [PATCH] fix(server): NER due to modules to skills refactoring --- server/src/core/ner.js | 6 +++--- server/src/core/nlu.js | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/server/src/core/ner.js b/server/src/core/ner.js index 47e85a8a..e578a05c 100644 --- a/server/src/core/ner.js +++ b/server/src/core/ner.js @@ -35,10 +35,10 @@ class Ner { const { classification } = obj // Remove end-punctuation and add an end-whitespace const utterance = `${string.removeEndPunctuation(obj.utterance)} ` - const utteranceSamplesObj = JSON.parse(fs.readFileSync(utteranceSamplesFilePath, 'utf8')) - const { module, action } = classification + const { actions } = JSON.parse(fs.readFileSync(utteranceSamplesFilePath, 'utf8')) + const { action } = classification const promises = [] - const actionEntities = utteranceSamplesObj[module][action].entities || [] + const actionEntities = actions[action].entities || [] /** * Browse action entities diff --git a/server/src/core/nlu.js b/server/src/core/nlu.js index 4e456f11..05386ea4 100644 --- a/server/src/core/nlu.js +++ b/server/src/core/nlu.js @@ -91,13 +91,13 @@ class Nlu { const { locale, domain, intent, score } = result - const [moduleName, actionName] = intent.split('.') + const [skillName, actionName] = intent.split('.') let obj = { utterance, entities: [], classification: { - package: domain, - module: moduleName, + domain, + skill: skillName, action: actionName, confidence: score } @@ -153,10 +153,11 @@ class Nlu { try { obj.entities = await this.ner.extractEntities( this.brain.lang, - join(__dirname, '../../../packages', obj.classification.package, `data/expressions/${this.brain.lang}.json`), + join(process.cwd(), 'skills', obj.classification.domain, obj.classification.skill, `nlu/${this.brain.lang}.json`), obj ) } catch (e) /* istanbul ignore next */ { + console.error(e) log[e.type](e.obj.message) if (!opts.mute) { @@ -176,6 +177,7 @@ class Nlu { nluProcessingTime: processingTime - data?.executionTime // In ms, NLU processing time only }) } catch (e) /* istanbul ignore next */ { + console.error(e) log[e.type](e.obj.message) if (!opts.mute) { @@ -207,8 +209,8 @@ class Nlu { if (JSON.stringify(tmpWords) === JSON.stringify(fallbacks[i].words)) { obj.entities = [] - obj.classification.package = fallbacks[i].package - obj.classification.module = fallbacks[i].module + obj.classification.domain = fallbacks[i].domain + obj.classification.skill = fallbacks[i].skill obj.classification.action = fallbacks[i].action obj.classification.confidence = 1