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

时间:2017-10-20 10:19:58

标签: java ibm-watson watson-conversation

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

#define UVAL ((unsigned)(VAL))

如何从输出回复中获取所有建议?

1 个答案:

答案 0 :(得分:1)

您可以使用上下文变量来保存用户使用<? input.text ?>所说的内容。尝试按照这个简单的例子:

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

{
  "context": {
    "userTypes": "<? input.text ?>"
  },
  "output": {
    "text": {
      "values": [
        "All you said here: $userTypes."
      ],
      "selection_policy": "sequential"
    }
  }
}

因此,在您的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();

     }
相关问题