2017-02-27 2 views
1

나는 기존의 폭포 대화를하고있다. 나는 로봇의 질문에 대한보다 복잡한 사용자 응답으로부터 데이터를 추출 할 수 있도록 그것을 적용하고 싶다.Microsoft Bot Framework LUIS in waterfall convers

내 LUIS 응용 프로그램에서는 Location이라는 엔티티를 찾을 수 있도록 훈련 된 GetLocation이라는 의도를 만들었습니다. 예를 들어 "Bristol에서 찾고있는"사용자가 "Bristol"엔터티와 일치하는 사용자입니다.

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 예제는 일치를 찾고 새로운 인 텐트로 이동하지만 폭포 대화를 계속 진행하기를 원합니다. LUIS를 어떻게 활용하면 좋을까요?

답변

0

나는 당신이 두 개의 서로 다른 대화 상자 설정을함으로써이 작업을 수행 할 수 있다고 생각 :

대화 1 :

이 위에있는 대화, 대화를 구동 정상적인 폭포의 대화입니다.

대화 2 :이 대화가 루이스 모델을 사용하여 루이스 의도 인식기로 생성됩니다

. 대화 상자 1은 프롬프트를 내 보낸 다음 사용자를이 대화 상자로 전달하고 사용자가 입력 한 텍스트를 구문 분석합니다. 모델은 이미 위치를 인식하도록 훈련되었으므로 엔터티를 추출하기 만하면됩니다.

대화 상자 2가 LUIS를 사용하여 위치 정보를 구문 분석하고 엔티티를 추출한 후에는 대화 상자를 끝내고 엔티티 (위치)를 대화 상자 1로 되돌려 놓습니다.이 대화 상자는 여전히 Dialog Stack에 있습니다.


코드 당신이 루이스에 대화를 통과 한 것입니다 당신이 위치를 사용자에게 메시지를 표시 한 다음 session.beginDialog("/begin_loc_parse")를 호출 루트 대화 상자에서 그래서 기본적으로


//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?"); 
}); 
, 의도 대화.

이 시점 이후에 사용자가 입력 한 모든 텍스트는 LUIS 모델에 의해 해석됩니다. 이를 통해 모델을 사용하여 사용자의 위치 정보를 인식하고 추출 할 수 있습니다.

그런 다음 키는 session.endDialogWithResult()을 사용하여 스택에서 LUIS 대화 상자를 팝하고 새로 추출 된 위치가있는 원래 폭포로 돌아갑니다.