From 7639f0e1d854de689b829d4398ec642893521924 Mon Sep 17 00:00:00 2001 From: Offer Akrabi Date: Tue, 27 Nov 2018 15:55:23 +0200 Subject: [PATCH 1/5] added filtering to nlu engine --- lib/nlu/bundles/engines/regexp/nlu.js | 20 +++++++++++++++++++- lib/nlu/intentity.js | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/nlu/bundles/engines/regexp/nlu.js b/lib/nlu/bundles/engines/regexp/nlu.js index 4997011..79570c0 100644 --- a/lib/nlu/bundles/engines/regexp/nlu.js +++ b/lib/nlu/bundles/engines/regexp/nlu.js @@ -65,7 +65,25 @@ class Nlu extends Base { ' confidence ' + intentity.getMaxIntentConfidence().toFixed(3) + ' ' + this.name + ' [' + intentity.getIntentName() + ', ' + intentity.getNumOfEntities() + '] ' + time.toFixed(3) + 'ms'); - // No match + + // filtering intents according to the intents.json file + const intent = intentity.getIntentName(); + if (intent !== undefined) { + // Visibility check + if (intent.visibility === 'hidden') { + intentity.removeIntent(intent); + } + // Entities fullfilment + if (intent.entities) { + for (const entity of intent.entities) { + if (entity.required) { + if (!intentity.getEntity(entity.name)) { + intentity.removeIntent((intent)); + } + } + } + } + } instrument.exitTime(request, "regexp", "evaluate"); cb(null, intentity); } diff --git a/lib/nlu/intentity.js b/lib/nlu/intentity.js index 03e0907..f122e94 100644 --- a/lib/nlu/intentity.js +++ b/lib/nlu/intentity.js @@ -88,6 +88,13 @@ Intentity.prototype.getIntentName = function (index) { return null; }; +Intentity.prototype.removeIntent = function(intentName) { + let index = this.intents.indexOf(intentName); + if(index > -1) { + this.intents.splice(index, 1); + } +}; + Intentity.prototype.getIntents = function () { return this.intents; }; From 0c498a35f2de08755008856a34c845e2454fafa7 Mon Sep 17 00:00:00 2001 From: Offer Akrabi Date: Tue, 27 Nov 2018 16:31:46 +0200 Subject: [PATCH 2/5] changed if statement --- lib/nlu/bundles/engines/regexp/nlu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nlu/bundles/engines/regexp/nlu.js b/lib/nlu/bundles/engines/regexp/nlu.js index 79570c0..8a8923b 100644 --- a/lib/nlu/bundles/engines/regexp/nlu.js +++ b/lib/nlu/bundles/engines/regexp/nlu.js @@ -68,7 +68,7 @@ class Nlu extends Base { // filtering intents according to the intents.json file const intent = intentity.getIntentName(); - if (intent !== undefined) { + if (intent) { // Visibility check if (intent.visibility === 'hidden') { intentity.removeIntent(intent); From 3fe6760c53c0432c72b95f3bd1c39e6e7abe84de Mon Sep 17 00:00:00 2001 From: Dean Haber <> Date: Tue, 11 Dec 2018 14:46:08 +0200 Subject: [PATCH 3/5] making some fixes --- lib/nlu/bundles/engines/regexp/nlu.js | 16 +++++----------- lib/nlu/factory.js | 6 +++--- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/nlu/bundles/engines/regexp/nlu.js b/lib/nlu/bundles/engines/regexp/nlu.js index 8a8923b..37bc360 100644 --- a/lib/nlu/bundles/engines/regexp/nlu.js +++ b/lib/nlu/bundles/engines/regexp/nlu.js @@ -66,13 +66,9 @@ class Nlu extends Base { ' ' + this.name + ' [' + intentity.getIntentName() + ', ' + intentity.getNumOfEntities() + '] ' + time.toFixed(3) + 'ms'); - // filtering intents according to the intents.json file + // filtering intents according to the intent.json file const intent = intentity.getIntentName(); if (intent) { - // Visibility check - if (intent.visibility === 'hidden') { - intentity.removeIntent(intent); - } // Entities fullfilment if (intent.entities) { for (const entity of intent.entities) { @@ -93,12 +89,10 @@ class Nlu extends Base { function load(self, resource, force, cb) { // Load the regular expression resource resource.intents.forEach(intent => { - if (intent.visibility !== 'gone') { - intent.grammar.forEach(item => { - let pattern = new Pattern(intent, item, resource); - self.patterns.push(pattern); - }); - } + intent.grammar.forEach(item => { + let pattern = new Pattern(intent, item, resource); + self.patterns.push(pattern); + }); }); //logger.debug(self.patterns); cb(); diff --git a/lib/nlu/factory.js b/lib/nlu/factory.js index 6f7aba7..8764cc1 100644 --- a/lib/nlu/factory.js +++ b/lib/nlu/factory.js @@ -102,7 +102,7 @@ class Factory { let promises = []; let types = manifest.nlu; types.forEach(function (type) { - promises.push(getNLU(type, manifest.name)); + promises.push(getNLU(type)); }); Promise.all(promises.map(reflect)).then(function (results) { @@ -125,7 +125,7 @@ class Factory { module.exports = Factory; -function getNLU(type, name) { +function getNLU(type) { return new Promise(function (resolve, reject) { let nlu; if(WaEnvUtils.isValidWaEnvVars() && type === 'wcs') { @@ -136,7 +136,7 @@ function getNLU(type, name) { if (!nlu) { reject(errors.couldNotReadNluType); } - nlu.name = name; + nlu.name = type; nlu.type = type; resolve(nlu) }).catch(function(err) { From 78d6decdff3e3452fc54327d83b0cc4eada86ffb Mon Sep 17 00:00:00 2001 From: Dean Haber <> Date: Tue, 11 Dec 2018 15:12:46 +0200 Subject: [PATCH 4/5] Some more small fixes for the intentity --- lib/nlu/bundles/engines/regexp/nlu.js | 10 ++++++++-- lib/nlu/intentity.js | 7 +++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/nlu/bundles/engines/regexp/nlu.js b/lib/nlu/bundles/engines/regexp/nlu.js index 37bc360..780df6d 100644 --- a/lib/nlu/bundles/engines/regexp/nlu.js +++ b/lib/nlu/bundles/engines/regexp/nlu.js @@ -13,6 +13,12 @@ const Intentity = require('../../../intentity'); const logger = require('../../../../logger'); const instrument = require('../../../../instrument'); +const path = require('path'); +const nluFolder = '/nlu/'; +const intentsFileName = 'intents.json'; +const intents = require(path.join(process.env.skillSDKResDir, nluFolder, intentsFileName)); + + class Nlu extends Base { constructor(name) { @@ -67,14 +73,14 @@ class Nlu extends Base { '] ' + time.toFixed(3) + 'ms'); // filtering intents according to the intent.json file - const intent = intentity.getIntentName(); + const intent = intents[intentity.getIntentName()]; if (intent) { // Entities fullfilment if (intent.entities) { for (const entity of intent.entities) { if (entity.required) { if (!intentity.getEntity(entity.name)) { - intentity.removeIntent((intent)); + intentity.removeIntent((intent.name)); } } } diff --git a/lib/nlu/intentity.js b/lib/nlu/intentity.js index f122e94..01efcfc 100644 --- a/lib/nlu/intentity.js +++ b/lib/nlu/intentity.js @@ -89,10 +89,9 @@ Intentity.prototype.getIntentName = function (index) { }; Intentity.prototype.removeIntent = function(intentName) { - let index = this.intents.indexOf(intentName); - if(index > -1) { - this.intents.splice(index, 1); - } + this.intents = this.intents.filter(function(intent) { + return intent.name !== intentName; + }); }; Intentity.prototype.getIntents = function () { From d0be1eeb07015e7bc4cc0503ac9cfd83c85247c0 Mon Sep 17 00:00:00 2001 From: Dean Haber <> Date: Tue, 11 Dec 2018 15:26:58 +0200 Subject: [PATCH 5/5] exposing the intents for testing --- lib/nlu/bundles/engines/regexp/nlu.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/nlu/bundles/engines/regexp/nlu.js b/lib/nlu/bundles/engines/regexp/nlu.js index 780df6d..3f840c5 100644 --- a/lib/nlu/bundles/engines/regexp/nlu.js +++ b/lib/nlu/bundles/engines/regexp/nlu.js @@ -16,14 +16,13 @@ const instrument = require('../../../../instrument'); const path = require('path'); const nluFolder = '/nlu/'; const intentsFileName = 'intents.json'; -const intents = require(path.join(process.env.skillSDKResDir, nluFolder, intentsFileName)); - class Nlu extends Base { constructor(name) { super(name); this.patterns = []; + this.intents = require(path.join(process.env.skillSDKResDir, nluFolder, intentsFileName)); } init(resource, force) { @@ -73,7 +72,7 @@ class Nlu extends Base { '] ' + time.toFixed(3) + 'ms'); // filtering intents according to the intent.json file - const intent = intents[intentity.getIntentName()]; + const intent = this.intents[intentity.getIntentName()]; if (intent) { // Entities fullfilment if (intent.entities) {