Skip to content

Commit

Permalink
Merge pull request #1217 from Apollon77/slot-enhance
Browse files Browse the repository at this point in the history
Enhance Slot-manager with additional informations and a method
  • Loading branch information
ericzon authored Jan 4, 2023
2 parents e11249f + dfc4588 commit 538c823
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/slot/src/slot-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ class SlotManager {
return Object.keys(this.intents[intent]);
}

/**
* Given an intent return the information if the intent has entities defined
*
* @param {String} intent Name of the intent.
* @returns {boolean} true if intent has defined entities, else false
*/
hasIntentEntities(intent) {
return this.getIntentEntityNames(intent).length > 0;
}

/**
* Clear the slot manager.
*/
Expand Down Expand Up @@ -243,7 +253,6 @@ class SlotManager {
const aliases = this.generateEntityAliases(result.entities);
for (let i = 0, l = result.entities.length; i < l; i += 1) {
const entity = result.entities[i];
console.log('handle entity', entity.option, entity.entity, aliases[i]);
// Remove existing mandatory entities to see what's left
delete mandatorySlots[entity.entity];
delete mandatorySlots[aliases[i]];
Expand All @@ -261,10 +270,14 @@ class SlotManager {
start: 0,
end: result.utterance.length - 1,
len: result.utterance.length,
isSlotFillingFallback: true,
});
delete mandatorySlots[context.slotFill.currentSlot];
}
keys = Object.keys(mandatorySlots);
if (context.slotFill && context.slotFill.currentSlot) {
context.slotFill.latestSlot = context.slotFill.currentSlot;
}
if (!keys || keys.length === 0) {
// All mandatory slots are filled, so we are done. No further questions needed
delete result.srcAnswer;
Expand All @@ -279,6 +292,7 @@ class SlotManager {
entities: result.entities,
answer: result.answer,
srcAnswer: result.srcAnswer,
latestSlot: context.slotFill.latestSlot,
};
const currentSlot = mandatorySlots[keys[0]];
result.slotFill.currentSlot = currentSlot.entity;
Expand Down
8 changes: 8 additions & 0 deletions packages/slot/test/slot-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ describe('Slot Manager', () => {
start: 0,
end: 4,
len: 5,
isSlotFillingFallback: true,
},
],
});
Expand Down Expand Up @@ -545,6 +546,7 @@ describe('Slot Manager', () => {
start: 0,
end: 4,
len: 5,
isSlotFillingFallback: true,
},
],
slotFill: {
Expand All @@ -559,9 +561,11 @@ describe('Slot Manager', () => {
sourceText: 'hello',
start: 0,
utteranceText: 'hello',
isSlotFillingFallback: true,
},
],
intent: 'intent',
latestSlot: 'entity1',
localeIso2: 'en',
srcAnswer: 'srcAnswer',
},
Expand Down Expand Up @@ -660,6 +664,7 @@ describe('Slot Manager', () => {
},
],
intent: 'intent',
latestSlot: 'entity1_1',
localeIso2: 'en',
srcAnswer: 'srcAnswer',
},
Expand Down Expand Up @@ -723,6 +728,7 @@ describe('Slot Manager', () => {
start: 0,
end: 4,
len: 5,
isSlotFillingFallback: true,
},
],
slotFill: {
Expand All @@ -746,9 +752,11 @@ describe('Slot Manager', () => {
start: 0,
end: 4,
len: 5,
isSlotFillingFallback: true,
},
],
intent: 'intent',
latestSlot: 'entity1_1',
localeIso2: 'en',
srcAnswer: 'srcAnswer',
},
Expand Down

0 comments on commit 538c823

Please sign in to comment.