Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions lib/nlu/bundles/engines/regexp/nlu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions lib/nlu/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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') {
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions lib/nlu/intentity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down