使用java获取Watson对话的所有输出

使用java获取Watson对话的所有输出,java,ibm-watson,watson-conversation,Java,Ibm Watson,Watson Conversation,如果我有一个IBM bluemix Watson对话对话框,输出JSON,如: "output": { "text": { "values": [ "What is your name?", "Name of the person?", "Please specify the name of the person." ], "selection_policy": "ra

如果我有一个IBM bluemix Watson对话对话框,输出JSON,如:

"output": {
    "text": {
        "values": [
            "What is your name?",
            "Name of the person?",
            "Please specify the name of the person."
        ],
        "selection_policy": "random",
        "append": true
    }
}

如何从输出响应中获取所有建议?

您可以使用上下文变量保存用户使用
所说的内容。请尝试遵循以下简单示例:

在上面的此节点中创建一个子节点,并添加:

{
  "context": {
    "userTypes": "<? input.text ?>"
  },
  "output": {
    "text": {
      "values": [
        "All you said here: $userTypes."
      ],
      "selection_policy": "sequential"
    }
  }
}
{
“背景”:{
“用户类型”:”
},
“产出”:{
“文本”:{
“价值观”:[
“你在这里说的一切:$userTypes。”
],
“选择策略”:“顺序”
}
}
}
因此,在Java示例中,您可以使用以下方法获取此上下文变量的值:

private Map<String, Object> context = new HashMap<>();

 ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_09_20);
 service.setUsernameAndPassword('Your Watson service UserName', 'Your watson service PassWord');
 MessageRequest newMessage = new MessageRequest.Builder().inputText(inputmessage).context(context).build();
 MessageResponse response = service.message('Your Workspace Id', newMessage).execute();

   //Passing Context of last conversation
    if(response.getContext() !=null)
      {
        context.clear();

        context = response.getContext();

     }
private Map context=new HashMap();
ConversationService=新的ConversationService(ConversationService.VERSION\u DATE\u 2016\u 09\u 20);
setUserName和PassWord('您的Watson服务用户名','您的Watson服务密码');
MessageRequest newMessage=newmessagerequest.Builder().inputText(inputmessage).context(context.build();
MessageResponse=service.message('您的工作区Id',newMessage).execute();
//传递上一次对话的上下文
if(response.getContext()!=null)
{
context.clear();
context=response.getContext();
}
  • 了解更多关于
  • 查看更多有关Watson内部对话的信息
  • 见官方使用Java
  • 请参阅Watson Developer Cloud中IBM Developer的一个