Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added filtering to nlu engine #67

Open
wants to merge 5 commits into
base: pre-release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 19 additions & 1 deletion lib/nlu/bundles/engines/regexp/nlu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/nlu/intentity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down