Botframework findEntity() issue

梦想与她 提交于 2019-12-08 15:14:36

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', [...]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!