Skip to content

Commit

Permalink
feat(server): main slots structure (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed Mar 22, 2022
1 parent 334bf39 commit 1d9b180
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
39 changes: 27 additions & 12 deletions scripts/train.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,41 @@ export default () => new Promise(async (resolve, reject) => {
const actionName = actionsKeys[k]
const actionObj = actions[actionName]
const intent = `${skillName}.${actionName}`
const { utterance_samples: utteranceSamples, answers } = actionObj
const { utterance_samples: utteranceSamples, answers, slots } = actionObj

nlp.assignDomain(lang, `${skillName}.${actionName}`, currentDomain.name)

/**
* TODO:
* 1. Merge person, location and organization to the
* NER before processing NLU (cf. line 210 in nlu.js): OK
* 2. Grab intents with slots
* 3. .addSlot() as per the slots config
* 4. Train resolvers (affirm_deny)
* 1. [OK] Merge person, location and organization to the
* NER before processing NLU (cf. line 210 in nlu.js)
* 2. [OK] Grab intents with slots
* 3. [OK] .addSlot() as per the slots config
* 4. Handle random questions picking
* 5. Train resolvers (affirm_deny: boolean value)
* 6. Map resolvers to skill actions
* 7. Utterance source type to get raw input from utterance
*/
if (intent === 'guess_the_number.start') {
console.log('iiin')
// nlp.slotManager.addSlot(intent, 'number', true, { [lang]: 'How many players?' })
// nlp.slotManager.addSlot(intent, 'person', true, { [lang]: 'How many players?' })
nlp.slotManager.addSlot(intent, 'boolean', true, { [lang]: 'How many players?' })
if (slots) {
for (let l = 0; l < slots.length; l += 1) {
const slotObj = slots[l]

/**
* TODO: handle entity within questions such as "Where does {{ hero }} live?"
* https://github.com/axa-group/nlp.js/issues/328
* https://github.com/axa-group/nlp.js/issues/291
* https://github.com/axa-group/nlp.js/issues/307
*/
if (slotObj.source.type === 'entity') {
nlp.slotManager
.addSlot(intent, slotObj.source.name, true, { [lang]: slotObj.questions })
}
/* nlp.slotManager
.addSlot(intent, 'boolean', true, { [lang]: 'How many players?' }) */
}
}

for (let l = 0; l < utteranceSamples.length; l += 1) {
for (let l = 0; l < utteranceSamples?.length; l += 1) {
nlp.addDocument(lang, utteranceSamples[l], intent)
}

Expand Down
17 changes: 6 additions & 11 deletions skills/games/guess_the_number/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
"slots": [
{
"name": "players_nb",
"entity": {
"source": {
"type": "entity",
"name": "number"
},
"answers": [
"questions": [
"How many players should I set?"
]
}
Expand All @@ -34,13 +35,6 @@
"I choose 73",
"86"
],
"slots": [
{
"name": "guess",
"entity": "number",
"lifespan": 1
}
],
"answers": {
"bigger": [
"The number is bigger.",
Expand All @@ -66,10 +60,11 @@
"slots": [
{
"name": "decision",
"resolver": {
"source": {
"type": "resolver",
"name": "affirm_deny"
},
"answers": [
"questions": [
"Would you like to play another round?"
]
}
Expand Down
15 changes: 1 addition & 14 deletions skills/leon/birthday/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"when_birthday": {
"type": "logic",
"utterance_samples": [
"When is Phoebe's birthday?",
""
"When is Phoebe's birthday?"
],
"entities": [
{
Expand All @@ -41,12 +40,6 @@
]
}
],
"slots": [
{
"name": "birth_date",
"entity": "date"
}
],
"answers": {
"birthday_found": [
"%person%'s birthday is the %birthday%",
Expand All @@ -72,12 +65,6 @@
"Note that my birthday is in April 12",
"The 30th May 1968 is my birth date"
],
"slots": [
{
"name": "birth_date",
"type": "date"
}
],
"answers": {
"birthday_understood": [
"Gotcha, your birth date is the %birth_date%.",
Expand Down
9 changes: 6 additions & 3 deletions skills/leon/color/nlu/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@
"color_meaning": {
"slots": [
{
"name": "color",
"entity": "color",
"answers": [
"name": "color_choice",
"source": {
"type": "entity",
"name": "color"
},
"questions": [
"What color do you want to know about?"
]
}
Expand Down

0 comments on commit 1d9b180

Please sign in to comment.