mirror of
https://github.com/leon-ai/leon.git
synced 2024-12-18 06:11:34 +03:00
refactor: normalize entities
This commit is contained in:
parent
9d6ae0aecd
commit
efc2a3a7c0
@ -56,7 +56,7 @@ class Conversation {
|
|||||||
entities
|
entities
|
||||||
} = contextObj
|
} = contextObj
|
||||||
const slotKeys = Object.keys(slots)
|
const slotKeys = Object.keys(slots)
|
||||||
|
|
||||||
// If slots are required to trigger next actions, then go through the context activation
|
// If slots are required to trigger next actions, then go through the context activation
|
||||||
if (slotKeys.length > 0) {
|
if (slotKeys.length > 0) {
|
||||||
const { actions } = JSON.parse(fs.readFileSync(nluDataFilePath, 'utf8'))
|
const { actions } = JSON.parse(fs.readFileSync(nluDataFilePath, 'utf8'))
|
||||||
@ -83,6 +83,9 @@ class Conversation {
|
|||||||
originalUtterance: contextObj.originalUtterance,
|
originalUtterance: contextObj.originalUtterance,
|
||||||
activatedAt: Date.now()
|
activatedAt: Date.now()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.title('Conversation')
|
||||||
|
log.info(`New active context: ${outputContext}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setSlots(lang, entities, slots)
|
this.setSlots(lang, entities, slots)
|
||||||
|
@ -56,12 +56,18 @@ class Ner {
|
|||||||
|
|
||||||
const { entities } = await this.ner.process({ locale: lang, text: utterance })
|
const { entities } = await this.ner.process({ locale: lang, text: utterance })
|
||||||
|
|
||||||
// Trim whitespace at the beginning and the end of the entity value
|
// Normalize entities
|
||||||
entities.map((e) => {
|
entities.map((entity) => {
|
||||||
e.sourceText = e.sourceText.trim()
|
// Trim whitespace at the beginning and the end of the entity value
|
||||||
e.utteranceText = e.utteranceText.trim()
|
entity.sourceText = entity.sourceText.trim()
|
||||||
|
entity.utteranceText = entity.utteranceText.trim()
|
||||||
|
|
||||||
return e
|
// Add resolution property to stay consistent with all entities
|
||||||
|
if (!entity.resolution) {
|
||||||
|
entity.resolution = { value: entity.sourceText }
|
||||||
|
}
|
||||||
|
|
||||||
|
return entity
|
||||||
})
|
})
|
||||||
|
|
||||||
if (entities.length > 0) {
|
if (entities.length > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user