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

标签 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": "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();

     }

关于java - 使用 java 获取 Watson 对话的所有输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46847072/

相关文章:

java - 如何调用这个实例方法

java - 单义性解析为 bean 结果为空值

node.js - 在 NodeJS 上为 Watson Conversation 配置 HTTPS

java - IBM Watson 无法在企业网络中工作

swift - 当我尝试在 Xcode 中导入 VisualRecognitionV3 时,它给出了用 swift 3.0 编译的错误模块无法在 swift 3.0.2 中导入?

java - 从主方法调用变量

java - 如何在jsp中循环对象的对象列表

watson-conversation - 在为 Watson Conversation API 流创建流时,我可以使用意图的置信度评级吗?

c# - IBM Watson 对话服务错误 : cannot convert from 'method group' to 'conversation.onMessage'

node.js - Watson 对话总是从根源开始