Java:如何从Google Dialogflow V2响应中提取参数 [英] Java : How to extract parameters from Google Dialogflow V2 response

查看:56
本文介绍了Java:如何从Google Dialogflow V2响应中提取参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何提取Google dialogflow v2响应返回的参数吗?我可以正确地获得意图和信心,因为可以使用高级方法.但是似乎没有方法可以获取参数/参数列表.响应包含具有参数的google protobuf Struct.有谁知道如何从中提取参数名称和值.

Does anyone know how to extract the parameters returned by the Google dialogflow v2 response? I am able to get the intents and confidence properly as there are high level methods available to do so. But it seems there is no method to get the parameters/list of params. The response contains a google protobuf Struct that has the params. Does anyone know how to extract the parameter names and values from it.

以下是示例回复

 query_text: "next friday"
parameters {
  fields {
    key: "appointmentDate"
    value {
      struct_value {
        fields {
          key: "date"
          value {
            string_value: "2019-05-31T12:00:00+10:00"
          }
        }
      }
    }
  }
}
all_required_params_present: true
fulfillment_messages {
  text {
    text: ""
  }
}
intent {
  name: "projects/dksjdkjsjksd-c824f/agent/intents/89a100c4973a"
  display_name: "captureDate"
}
intent_detection_confidence: 1.0
language_code: "en"

推荐答案

我太专心于分析原型缓冲区并将其映射到Java bean.花了几个小时并发布了一个问题之后,我想到了一个简单的想法,以找到一种将原始缓冲区转换为json的方法.然后一切都很简单,因为我找到了这个API

I was too focussed to parse and map the proto buffer to a Java bean. After spending hours and posting a question, a simple thought striked to my mind to find a way to convert the proto buffer to a json. And then it was all simple because I found this API

JsonFormat.printToString(protoMessage)

这听起来很简单,但这仅仅是因为我改变了解决问题的策略,从学习原型缓冲区并对其进行解码,改为使用原型转换为json转换器并使用json格式,这会更好地理解.

It sounds simple now but that is all because I changed my problem solving strategy from learning proto buffer and decoding it, to rather use a proto to json convertor and work with json format, which understand much better.

这篇关于Java:如何从Google Dialogflow V2响应中提取参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆