diff --git a/lib/nlu/bundles/engines/regexp/nlu.js b/lib/nlu/bundles/engines/regexp/nlu.js index 4997011..3f840c5 100644 --- a/lib/nlu/bundles/engines/regexp/nlu.js +++ b/lib/nlu/bundles/engines/regexp/nlu.js @@ -13,11 +13,16 @@ const Intentity = require('../../../intentity'); const logger = require('../../../../logger'); const instrument = require('../../../../instrument'); +const path = require('path'); +const nluFolder = '/nlu/'; +const intentsFileName = 'intents.json'; + class Nlu extends Base { constructor(name) { super(name); this.patterns = []; + this.intents = require(path.join(process.env.skillSDKResDir, nluFolder, intentsFileName)); } init(resource, force) { @@ -65,7 +70,21 @@ 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 intent.json file + const intent = this.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.name)); + } + } + } + } + } instrument.exitTime(request, "regexp", "evaluate"); cb(null, intentity); } @@ -75,12 +94,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) { diff --git a/lib/nlu/intentity.js b/lib/nlu/intentity.js index 03e0907..01efcfc 100644 --- a/lib/nlu/intentity.js +++ b/lib/nlu/intentity.js @@ -88,6 +88,12 @@ Intentity.prototype.getIntentName = function (index) { return null; }; +Intentity.prototype.removeIntent = function(intentName) { + this.intents = this.intents.filter(function(intent) { + return intent.name !== intentName; + }); +}; + Intentity.prototype.getIntents = function () { return this.intents; };