Is there any way to avail of the WDS query "passage" feature via the Java APIs?

时间:2017-06-15 10:01:24

标签: ibm-watson watson-discovery

The Watson Discovery Service Java APIs allow a consumer to specify:

  • query
  • aggregation
  • count
  • filter
  • offset
  • returnFields

via com.ibm.watson.developer_cloud.discovery.v1.model.query.QueryRequest.Builder

There appears (as of version 3.8.0) to be no way to set passages=true though? Is this feature coming/planned?

2 个答案:

答案 0 :(得分:0)

您需要在通话中设置查询选项。

在文档中显示您需要为此做些什么。您需要在调用query.Builder()

中设置query_options

使用cURL,您将设置:

curl -u "{username}":"{password}}" "https://gateway.watsonplatform.net/discovery/api/v1/environments/{environment_id}/collections/{collection_id}/query?version=2016-12-01&natural_language_query='collie'&passages=true"

使用Java,您需要设置如下内容:

Discovery discovery = new Discovery("2016-12-01");
discovery.setEndPoint("https://gateway.watsonplatform.net/discovery/api/v1");
discovery.setUsernameAndPassword("{username}", "{password}");
String environmentId = "{environment_id}";
String collectionId = "{collection_id}";
String queryOptions = { "passages": true };

QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionId, queryOptions);
queryBuilder.query("{field}:{value}");
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();

Obs。:在文档中说: query_options 指定查询的参数。 在Java和Node中,将其指定为查询string

有关字符串或字典内容的信息,请参阅查询选项表。 请参阅官方参考here

答案 1 :(得分:0)

答案是,在Java客户端v4.0(2017年9月发布)之前,该功能尚未得到支持

功能现已上市。