1
1
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:
louistiti 2022-04-05 10:41:18 +08:00
parent 9d6ae0aecd
commit efc2a3a7c0
No known key found for this signature in database
GPG Key ID: 0A1C3B043E70C77D
2 changed files with 15 additions and 6 deletions

View File

@ -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)

View File

@ -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 })
// Normalize entities
entities.map((entity) => {
// Trim whitespace at the beginning and the end of the entity value // Trim whitespace at the beginning and the end of the entity value
entities.map((e) => { entity.sourceText = entity.sourceText.trim()
e.sourceText = e.sourceText.trim() entity.utteranceText = entity.utteranceText.trim()
e.utteranceText = e.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) {