1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-12-18 14:21:32 +03:00

fix(server): NER due to modules to skills refactoring

This commit is contained in:
louistiti 2022-02-14 16:48:03 +08:00
parent 65398d8231
commit e4d3904cee
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
2 changed files with 11 additions and 9 deletions

View File

@ -35,10 +35,10 @@ class Ner {
const { classification } = obj const { classification } = obj
// Remove end-punctuation and add an end-whitespace // Remove end-punctuation and add an end-whitespace
const utterance = `${string.removeEndPunctuation(obj.utterance)} ` const utterance = `${string.removeEndPunctuation(obj.utterance)} `
const utteranceSamplesObj = JSON.parse(fs.readFileSync(utteranceSamplesFilePath, 'utf8')) const { actions } = JSON.parse(fs.readFileSync(utteranceSamplesFilePath, 'utf8'))
const { module, action } = classification const { action } = classification
const promises = [] const promises = []
const actionEntities = utteranceSamplesObj[module][action].entities || [] const actionEntities = actions[action].entities || []
/** /**
* Browse action entities * Browse action entities

View File

@ -91,13 +91,13 @@ class Nlu {
const { const {
locale, domain, intent, score locale, domain, intent, score
} = result } = result
const [moduleName, actionName] = intent.split('.') const [skillName, actionName] = intent.split('.')
let obj = { let obj = {
utterance, utterance,
entities: [], entities: [],
classification: { classification: {
package: domain, domain,
module: moduleName, skill: skillName,
action: actionName, action: actionName,
confidence: score confidence: score
} }
@ -153,10 +153,11 @@ class Nlu {
try { try {
obj.entities = await this.ner.extractEntities( obj.entities = await this.ner.extractEntities(
this.brain.lang, 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 obj
) )
} catch (e) /* istanbul ignore next */ { } catch (e) /* istanbul ignore next */ {
console.error(e)
log[e.type](e.obj.message) log[e.type](e.obj.message)
if (!opts.mute) { if (!opts.mute) {
@ -176,6 +177,7 @@ class Nlu {
nluProcessingTime: processingTime - data?.executionTime // In ms, NLU processing time only nluProcessingTime: processingTime - data?.executionTime // In ms, NLU processing time only
}) })
} catch (e) /* istanbul ignore next */ { } catch (e) /* istanbul ignore next */ {
console.error(e)
log[e.type](e.obj.message) log[e.type](e.obj.message)
if (!opts.mute) { if (!opts.mute) {
@ -207,8 +209,8 @@ class Nlu {
if (JSON.stringify(tmpWords) === JSON.stringify(fallbacks[i].words)) { if (JSON.stringify(tmpWords) === JSON.stringify(fallbacks[i].words)) {
obj.entities = [] obj.entities = []
obj.classification.package = fallbacks[i].package obj.classification.domain = fallbacks[i].domain
obj.classification.module = fallbacks[i].module obj.classification.skill = fallbacks[i].skill
obj.classification.action = fallbacks[i].action obj.classification.action = fallbacks[i].action
obj.classification.confidence = 1 obj.classification.confidence = 1