I've encountered a strange problem. Originally I had this to get my entity and it works correctly.
x = builder.EntityRecognizer.findEntity(args.entities, 'get_x');
However, for some reason I can't seem to figure out why, it stopped working and I had to change it to adding an additional intent
to get it to work again.
x = builder.EntityRecognizer.findEntity(args.intent.entities, 'get_x');
I was changing one of my intents on LUIS when I think this started to happen. Then I immediately undo all the changes to that intent, however all my intents were somehow affected to that as I need to add another additional intent
to my entities parameter of the findEntity()
method.
Is there something that I changed that could have cause this?
Edit: Actually changing my LUIS intents shouldn't have affected it as I've another bot using the same LUIS model and it's still working correctly.
Edit2: My args
returns me this:
{ action: '*:SomeIntent',
intent:
{ score: 0.999846458,
intent: 'SomeIntent',
intents:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ],
entities: [ [Object], [Object], [Object], [Object] ] },
libraryName: '*' }
Originally I could just use args.entities
to find my entity but now the format changed and I've to use args.intent.entities
to find my entity.
I found examples where this one uses args.entities
while this one uses args.intent.entities
. I know this doesn't really affect me that much as I can just change my code but I'm curious to know why this happens?
Thanks.
Have you checked the initialization of your bots' LuisRecognizers and compared them to each other? They most likely have a slight difference in code, the BotBuilder-Sample/Node/intelligence-LUIS example uses only the botbuilder's LuisRecognizer on line 27.
var recognizer = new builder.LuisRecognizer(process.env.LUIS_MODEL_URL); // Line 27
bot.recognizer(recognizer);
bot.dialog('SearchHotels', [
function (session, args, next) {
...
var cityEntity = builder.EntityRecognizer.findEntity(args.intents.entities, 'builtin.geography.city');
If only using the LuisRecognizer, you will need to use args.intent.entities
instead of args.entities
.
If you use IntentDialog with LuisRecognizer, the setup is different in that you pass in var recognizer = new builder.LuisRecognizer(<model>)
to new builder.IntentDialog({ recognizers: [recognizer] })
. The object inside of IntentDialog is the only parameter it receives in its construction, and the optional property recognizers
takes an array of IIntentRecognizers (which is implemented by the LuisRecognizer).
The code below is taken from the Entity Recognition section of the Intent Dialog docs (your first example):
var recognizer = new builder.LuisRecognizer('<your models url>');
var intents = new builder.IntentDialog({ recognizers: [recognizer] });
bot.dialog('/', intents);
intents.matches('AddTask', [
function (session, args, next) {
var task = builder.EntityRecognizer.findEntity(args.entities, 'TaskTitle');
if (!task) {
builder.Prompts.text(session, "What would you like to call the task?");
} else {
next({ response: task.entity });
}
},
...
]);
intents.matches()
will pass the full details of the match to the first step in the waterfall or dialog after an intent is matched. However, it will parse down to the intent property/object, meaning instead of having to use args.intent.entities
you only use args.entities
.
Edit:
Ah, that may have been it. For some reason I remember it working right after I changed it. Just wondering, are there any pros and cons between the two? Or just coding style that's different?
It's not necessarily a pros-and-cons item, but the difference between the two methods is that in the first method you'll only be able to incorporate a single Luis model. (See below)
var mySingleRecognizer = new builder.LuisRecognizer(<model>);
bot.recognizer(mySingleRecognizer);
However, if you use IntentDialog({ recognizers: ... })
you'll be able to pass in an array of recognizers; for example multiple LUIS models...
var HotelRecognizer = new builder.LuisRecognizer(<HotelModel>);
var DogRecognizer = new builder.LuisRecognizer(<DogModel>);
Or even different types of recognizers...
var RegularRecognizer = new builder.RegExpRecognizer('Cats', /^cat$/i);
Into your IntentDialog:
var intents = new builder.IntentDialog({ recognizers: [HotelRecognizer, DogRecognizer, RegularRecognizer] });
intents.matches('GetDog', [...]);
intents.matches('SearchHotels', [...]);
intents.matches('Cats', [...]);
来源:https://stackoverflow.com/questions/43194594/botframework-findentity-issue