Search in sources :

Example 81 with RequestBuilder

use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class Discovery method query.

/**
 * Query documents.
 *
 * See the [Discovery service documentation](https://console.bluemix.net/docs/services/discovery/using.html) for more
 * details.
 *
 * @param queryOptions the {@link QueryOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link QueryResponse}
 */
public ServiceCall<QueryResponse> query(QueryOptions queryOptions) {
    Validator.notNull(queryOptions, "queryOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "query" };
    String[] pathParameters = { queryOptions.environmentId(), queryOptions.collectionId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (queryOptions.filter() != null) {
        builder.query("filter", queryOptions.filter());
    }
    if (queryOptions.query() != null) {
        builder.query("query", queryOptions.query());
    }
    if (queryOptions.naturalLanguageQuery() != null) {
        builder.query("natural_language_query", queryOptions.naturalLanguageQuery());
    }
    if (queryOptions.passages() != null) {
        builder.query("passages", String.valueOf(queryOptions.passages()));
    }
    if (queryOptions.aggregation() != null) {
        builder.query("aggregation", queryOptions.aggregation());
    }
    if (queryOptions.count() != null) {
        builder.query("count", String.valueOf(queryOptions.count()));
    }
    if (queryOptions.returnFields() != null) {
        builder.query("return", RequestUtils.join(queryOptions.returnFields(), ","));
    }
    if (queryOptions.offset() != null) {
        builder.query("offset", String.valueOf(queryOptions.offset()));
    }
    if (queryOptions.sort() != null) {
        builder.query("sort", RequestUtils.join(queryOptions.sort(), ","));
    }
    if (queryOptions.highlight() != null) {
        builder.query("highlight", String.valueOf(queryOptions.highlight()));
    }
    if (queryOptions.passagesFields() != null) {
        builder.query("passages.fields", RequestUtils.join(queryOptions.passagesFields(), ","));
    }
    if (queryOptions.passagesCount() != null) {
        builder.query("passages.count", String.valueOf(queryOptions.passagesCount()));
    }
    if (queryOptions.passagesCharacters() != null) {
        builder.query("passages.characters", String.valueOf(queryOptions.passagesCharacters()));
    }
    if (queryOptions.deduplicate() != null) {
        builder.query("deduplicate", String.valueOf(queryOptions.deduplicate()));
    }
    if (queryOptions.deduplicateField() != null) {
        builder.query("deduplicate.field", queryOptions.deduplicateField());
    }
    if (queryOptions.similar() != null) {
        builder.query("similar", String.valueOf(queryOptions.similar()));
    }
    if (queryOptions.similarDocumentIds() != null) {
        builder.query("similar.document_ids", RequestUtils.join(queryOptions.similarDocumentIds(), ","));
    }
    if (queryOptions.similarFields() != null) {
        builder.query("similar.fields", RequestUtils.join(queryOptions.similarFields(), ","));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(QueryResponse.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) QueryResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse)

Example 82 with RequestBuilder

use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class Discovery method getCollection.

/**
 * Get collection details.
 *
 * @param getCollectionOptions the {@link GetCollectionOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Collection}
 */
public ServiceCall<Collection> getCollection(GetCollectionOptions getCollectionOptions) {
    Validator.notNull(getCollectionOptions, "getCollectionOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections" };
    String[] pathParameters = { getCollectionOptions.environmentId(), getCollectionOptions.collectionId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Collection.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection)

Example 83 with RequestBuilder

use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class Discovery method deleteCollection.

/**
 * Delete a collection.
 *
 * @param deleteCollectionOptions the {@link DeleteCollectionOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of Void
 */
public ServiceCall<Void> deleteCollection(DeleteCollectionOptions deleteCollectionOptions) {
    Validator.notNull(deleteCollectionOptions, "deleteCollectionOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections" };
    String[] pathParameters = { deleteCollectionOptions.environmentId(), deleteCollectionOptions.collectionId() };
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder)

Example 84 with RequestBuilder

use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class Discovery method getConfiguration.

/**
 * Get configuration details.
 *
 * @param getConfigurationOptions the {@link GetConfigurationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Configuration}
 */
public ServiceCall<Configuration> getConfiguration(GetConfigurationOptions getConfigurationOptions) {
    Validator.notNull(getConfigurationOptions, "getConfigurationOptions cannot be null");
    String[] pathSegments = { "v1/environments", "configurations" };
    String[] pathParameters = { getConfigurationOptions.environmentId(), getConfigurationOptions.configurationId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Configuration.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)

Example 85 with RequestBuilder

use of com.ibm.watson.developer_cloud.http.RequestBuilder 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

RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)206 JsonObject (com.google.gson.JsonObject)60 MultipartBody (okhttp3.MultipartBody)10 RequestBody (okhttp3.RequestBody)10 Counterexample (com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample)3 DialogNode (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode)3 Example (com.ibm.watson.developer_cloud.assistant.v1.model.Example)3 Synonym (com.ibm.watson.developer_cloud.assistant.v1.model.Synonym)3 Counterexample (com.ibm.watson.developer_cloud.conversation.v1.model.Counterexample)3 DialogNode (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)3 Example (com.ibm.watson.developer_cloud.conversation.v1.model.Example)3 Synonym (com.ibm.watson.developer_cloud.conversation.v1.model.Synonym)3 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)3 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)3 Environment (com.ibm.watson.developer_cloud.discovery.v1.model.Environment)3 Entity (com.ibm.watson.developer_cloud.assistant.v1.model.Entity)2 Intent (com.ibm.watson.developer_cloud.assistant.v1.model.Intent)2 LogCollection (com.ibm.watson.developer_cloud.assistant.v1.model.LogCollection)2 Value (com.ibm.watson.developer_cloud.assistant.v1.model.Value)2 Workspace (com.ibm.watson.developer_cloud.assistant.v1.model.Workspace)2