2017-02-27 55 views
1

我有一個現有的瀑布交談。我想調整它,以便從更復雜的用戶對機器人問題的響應中提取數據。微軟博客框架LUIS在瀑布交談

在我的LUIS應用程序中,我創建了一個名爲GetLocation的意圖,該意向被訓練以找到名爲Location的實體。例如,用戶鍵入「我正在尋找布裏斯托爾」,這將匹配實體「布裏斯托爾」。這是我目前有:

function(session) { 
     builder.Prompts.text(session, "Hello... Which city are you looking in?"); 
}, 
function(session, results) { 
    session.privateConversationData.city = results.response; 
    builder.Prompts.number(session, "Ok, you are looking in " + results.response + ", How many bedrooms are you looking for?"); 
}, 
etc... 

而不是簡單地存儲響應字符串,我想發送的響應串關路易斯並從中提取了城市的位置。我發現的所有LUIS例子都是用於匹配並轉向新的intents,但我只是想保持瀑布式對話。我將如何利用LUIS來做到這一點?

回答

0

我認爲你可以有兩個不同的對話框設置做到這一點:

對話1:

這是你有上面的對話框,驅動談話正常的瀑布對話框。

對話2:

這個對話框會使用您LUIS模型LUIS意圖識別器來創建。對話框1將發出提示,然後將用戶傳遞給此對話框並解析用戶輸入的文本。由於您的模型已經接受了識別位置的培訓,您現在需要做的就是提取實體。

對話框2使用LUIS解析位置信息並提取實體後,將結束對話框並將實體(位置)返回到對話框1,該對話框仍將位於Dialog Stack上。


代碼

//create intent recognizer based on LUIS model 
var luisModel = "<Your LUIS Model URL>"; 
var recognizer = new botbuilder.LuisRecognizer(luisModel); 
//create dialog handler for info to be parsed by LUIS 
var dialog = new botbuilder.IntentDialog({ recognizers: [recognizer] }); 

//root dialog 
bot.dialog("/", [ 
    function(session){ 

     //prompt user and pop LUIS intent dialog onto dialog stack 
     session.send("Hello, which city are you looking in?"); 
     session.beginDialog("/begin_loc_parse"); 

    }, 

    //this will be resumed after our location has been extracted 
    function(session, results){ 

     //check for extracted location 
     if(results.entity){ 
      //got location successfully 
      session.send("Got city from user: " + results.entity); 

      //resume normal waterfall with location..... 

     } else { 
      //start over 
      session.beginDialog("/"); 
     } 
    } 
]); 

//LUIS intent dialog 
dialog.matches("input_location", function(session, args){ 

    //grab location entity 
    var city = botbuilder.EntityRecognizer.findEntity(args.entities, "builtin.geography.city"); 

    if(city){ 
     //pop the LUIS dialog off of the dialog stack 
     //and return the extracted location back to waterfall 
     session.endDialogWithResult(city); 
    } else session.endDialog("Couldn't extract city entity."); 

}); 

//called if user doesn't enter something like "I am looking in [city]" 
dialog.onDefault(function(session, args){ 
    session.send("I'm sorry, I didn't quite catch that. In which city are you looking?"); 
}); 

因此,基本上,在根對話框,當您提示的位置的用戶,然後調用session.beginDialog("/begin_loc_parse")你會通過談話您LUIS意圖對話。

用戶在此點之後輸入的任何文本都將被LUIS模型解釋。這使您可以使用模型來識別並提取用戶的位置信息。

然後,關鍵是使用session.endDialogWithResult()從堆棧中彈出LUIS對話框,並使用新提取的位置返回到原始瀑布。