Skip to content

Commit

Permalink
feat(server): support on-the-fly entity annotation for built-in entities
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed Jun 10, 2022
1 parent 2ac1bc6 commit 567b030
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
3 changes: 1 addition & 2 deletions core/data/en/resolvers/affirmation_denial.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"That's right",
"That works",
"Go ahead",
"Why not",
"I do"
"Why not"
],
"value": true
},
Expand Down
2 changes: 2 additions & 0 deletions scripts/train.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export default () => new Promise(async (resolve, reject) => {
const intentName = intentKeys[j]
const intentObj = resolverIntents[intentName]

nlp.assignDomain(lang, intentName, 'system')

for (let k = 0; k < intentObj.utterance_samples.length; k += 1) {
nlp.addDocument(lang, intentObj.utterance_samples[k], intentName)
}
Expand Down
12 changes: 10 additions & 2 deletions server/src/core/brain.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ class Brain {
const nextAction = action.next_action ? actions[action.next_action] : null

if (actionType === 'logic') {
/**
* "Logic" action skill execution
*/

// Ensure the process is empty (to be able to execute other processes outside of Brain)
if (Object.keys(this.process).length === 0) {
/**
Expand Down Expand Up @@ -335,6 +339,10 @@ class Brain {
// Reset the child process
this.process = { }
} else {
/**
* "Dialog" action skill execution
*/

const nluFilePath = path.join(
process.cwd(), 'skills', obj.classification.domain, obj.classification.skill, 'nlu', `${this._lang}.json`
)
Expand Down Expand Up @@ -369,9 +377,9 @@ class Brain {
*/
if (utteranceHasEntities && answer.indexOf('{{') !== -1) {
obj.entities.forEach((entityObj) => {
answer = string.pnr(answer, { [`{{ ${entityObj.entity} }}`]: entityObj.option })
answer = string.pnr(answer, { [`{{ ${entityObj.entity} }}`]: entityObj.resolution.value })

// Find matches and map deeper data from the NLU file
// Find matches and map deeper data from the NLU file (global/custom entities)
const matches = answer.match(/{{.+?}}/g)

matches?.forEach((match) => {
Expand Down
2 changes: 1 addition & 1 deletion skills/leon/introduction/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"name": "date"
},
"questions": [
"What's your birth date?"
"What's your birth date {{ person }}?"
]
}
],
Expand Down
8 changes: 4 additions & 4 deletions skills/leon/partner_assistant/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"partner_assistant": {
"options": {
"Alexa": {
"synonyms": ["alexa"],
"synonyms": ["Alexa"],
"data": {
"thought": [
"Alexa is very kind and Amazon is teaching it many things. It was born in November 2014.",
Expand All @@ -31,7 +31,7 @@
}
},
"Cortana": {
"synonyms": ["cortana"],
"synonyms": ["Cortana"],
"data": {
"thought": [
"Cortana is thoughtful and Microsoft is improving her day after day. She was born in April 2014.",
Expand All @@ -40,7 +40,7 @@
}
},
"Siri": {
"synonyms": ["siri"],
"synonyms": ["Siri"],
"data": {
"thought": [
"I consider Siri as a leader, it has a lot of experience and Apple is constantly improving it. It was born in October 2011.",
Expand All @@ -49,7 +49,7 @@
}
},
"Google Assistant": {
"synonyms": ["google assistant"],
"synonyms": ["Google Assistant"],
"data": {
"thought": [
"Google Assistant is smart and Google is doing a great job with it. It was born in May 2016.",
Expand Down

0 comments on commit 567b030

Please sign in to comment.