diff --git a/packages/slot/src/slot-manager.js b/packages/slot/src/slot-manager.js index 130857bda..f2cd747e0 100644 --- a/packages/slot/src/slot-manager.js +++ b/packages/slot/src/slot-manager.js @@ -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. */ @@ -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]]; @@ -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; @@ -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; diff --git a/packages/slot/test/slot-manager.test.js b/packages/slot/test/slot-manager.test.js index f2d511b8d..1b2d9cb58 100644 --- a/packages/slot/test/slot-manager.test.js +++ b/packages/slot/test/slot-manager.test.js @@ -444,6 +444,7 @@ describe('Slot Manager', () => { start: 0, end: 4, len: 5, + isSlotFillingFallback: true, }, ], }); @@ -545,6 +546,7 @@ describe('Slot Manager', () => { start: 0, end: 4, len: 5, + isSlotFillingFallback: true, }, ], slotFill: { @@ -559,9 +561,11 @@ describe('Slot Manager', () => { sourceText: 'hello', start: 0, utteranceText: 'hello', + isSlotFillingFallback: true, }, ], intent: 'intent', + latestSlot: 'entity1', localeIso2: 'en', srcAnswer: 'srcAnswer', }, @@ -660,6 +664,7 @@ describe('Slot Manager', () => { }, ], intent: 'intent', + latestSlot: 'entity1_1', localeIso2: 'en', srcAnswer: 'srcAnswer', }, @@ -723,6 +728,7 @@ describe('Slot Manager', () => { start: 0, end: 4, len: 5, + isSlotFillingFallback: true, }, ], slotFill: { @@ -746,9 +752,11 @@ describe('Slot Manager', () => { start: 0, end: 4, len: 5, + isSlotFillingFallback: true, }, ], intent: 'intent', + latestSlot: 'entity1_1', localeIso2: 'en', srcAnswer: 'srcAnswer', },