Socket
Socket
Sign inDemoInstall

@nlpjs/slot

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nlpjs/slot - npm Package Compare versions

Comparing version 4.22.17 to 4.25.0

4

package.json
{
"name": "@nlpjs/slot",
"version": "4.22.17",
"version": "4.25.0",
"description": "Slot filling manager",

@@ -27,3 +27,3 @@ "author": {

},
"gitHead": "6afb044a488a67999fad66362241b25784098c0a"
"gitHead": "3065165b42ea2160d2a27c10c412c4b4c491332a"
}

@@ -63,4 +63,4 @@ /*

* @param {String} entity Name of the entity.
* @param {boolean} mandatory Flag indicating if is mandatory or optional.
* @param {Object} questions Question to ask when is mandatory, by locale.
* @param {boolean} [mandatory=false] Flag indicating if is mandatory or optional.
* @param {Object} [questions] Question to ask when is mandatory, by locale.
* @returns {Object} New slot instance.

@@ -83,2 +83,25 @@ */

/**
* Adds/modifies the parameter of a slot for a given intent and entity.
* Slot questions for same locales as already existing will be overwritten.
* If the slot for the intent and entity does not exist it fill be created.
* @param {String} intent Name of the intent.
* @param {String} entity Name of the entity.
* @param {boolean} mandatory Flag indicating if is mandatory or optional.
* @param {Object} [questions] Question to ask when is mandatory, by locale.
* @returns {Object} New/Modified slot instance or undefined if not existing
*/
updateSlot(intent, entity, mandatory, questions) {
if (!this.intents[intent] || !this.intents[intent][entity]) {
return this.addSlot(intent, entity, mandatory, questions);
}
const slot = this.intents[intent][entity];
if (mandatory !== undefined) {
// Update mandatory flag only if provided
slot.mandatory = mandatory;
}
slot.locales = Object.assign(slot.locales, questions);
return this.intents[intent][entity];
}
/**
* Remove an slot given the intent and the entity.

@@ -185,2 +208,16 @@ * @param {String} intent Name of the intent.

generateEntityAliases(entities) {
const aliases = [];
const dict = {};
for (let i = 0; i < entities.length; i += 1) {
const entity = entities[i];
if (!dict[entity.entity]) {
dict[entity.entity] = [];
}
aliases[i] = `${entity.entity}_${dict[entity.entity].length}`;
dict[entity.entity].push(true);
}
return aliases;
}
process(srcResult, srcContext) {

@@ -191,2 +228,3 @@ const result = srcResult;

if (context.slotFill) {
// if we have slotFill values we set the context to be the same as before
result.intent = context.slotFill.intent;

@@ -197,2 +235,3 @@ result.answer = context.slotFill.answer;

if (!result.intent || result.intent === 'None') {
// No intent found, we repeat the answer from last time
return false;

@@ -206,5 +245,18 @@ }

if (keys.length === 0) {
// No mandatory entities defined, we repeat the answer from last time
return false;
}
if (context.slotFill) {
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]];
}
if (context.slotFill && mandatorySlots[context.slotFill.currentSlot]) {
// Last time requested slot was not filled by current answer automatically,
// so add whole utterance as answer for the requested slow
// Do this because automatically parsed entities by builtins like "duration" are
// added automatically, and we don't want to have duplicated entries in the list
result.entities.push({

@@ -219,8 +271,8 @@ entity: context.slotFill.currentSlot,

});
delete mandatorySlots[context.slotFill.currentSlot];
}
for (let i = 0, l = result.entities.length; i < l; i += 1) {
delete mandatorySlots[result.entities[i].entity];
}
keys = Object.keys(mandatorySlots);
if (!keys || keys.length === 0) {
// All mandatory slots are filled, so we are done. No further questions needed
delete result.srcAnswer;
return true;

@@ -227,0 +279,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc