如果我有一个 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
}
}
如何从输出响应中获取所有建议?
最佳答案
您可以使用上下文变量来保存用户所说的内容,使用 <? input.text ?>
。尝试遵循这个简单的例子:
在上面这个Node中创建一个子节点,并添加:
{
"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();
}
- 查看更多有关 Accessing and Evaluate objects 的信息.
- 查看更多有关 methods 的信息在 Watson Conversation 中。
- 查看官方API Reference使用 Java。
- 查看一个 full example来自 Watson Developer Cloud 中的 IBM Developer。
关于java - 使用 java 获取 Watson 对话的所有输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46847072/