Search in sources :

Example 1 with QueryEntitiesResponse

use of com.ibm.watson.developer_cloud.discovery.v1.model.QueryEntitiesResponse in project java-sdk by watson-developer-cloud.

the class Discovery method queryEntities.

/**
 * Knowledge Graph entity query.
 *
 * See the [Knowledge Graph documentation](https://console.bluemix.net/docs/services/discovery/building-kg.html) for
 * more details.
 *
 * @param queryEntitiesOptions the {@link QueryEntitiesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link QueryEntitiesResponse}
 */
public ServiceCall<QueryEntitiesResponse> queryEntities(QueryEntitiesOptions queryEntitiesOptions) {
    Validator.notNull(queryEntitiesOptions, "queryEntitiesOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "query_entities" };
    String[] pathParameters = { queryEntitiesOptions.environmentId(), queryEntitiesOptions.collectionId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (queryEntitiesOptions.feature() != null) {
        contentJson.addProperty("feature", queryEntitiesOptions.feature());
    }
    if (queryEntitiesOptions.entity() != null) {
        contentJson.add("entity", GsonSingleton.getGson().toJsonTree(queryEntitiesOptions.entity()));
    }
    if (queryEntitiesOptions.context() != null) {
        contentJson.add("context", GsonSingleton.getGson().toJsonTree(queryEntitiesOptions.context()));
    }
    if (queryEntitiesOptions.count() != null) {
        contentJson.addProperty("count", queryEntitiesOptions.count());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(QueryEntitiesResponse.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) QueryEntitiesResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryEntitiesResponse)

Aggregations

JsonObject (com.google.gson.JsonObject)1 QueryEntitiesResponse (com.ibm.watson.developer_cloud.discovery.v1.model.QueryEntitiesResponse)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1