Search in sources :

Example 1 with AddTrainingDataOptions

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

the class Discovery method addTrainingData.

/**
 * Adds a query to the training data for this collection. The query can contain a filter and natural language query.
 *
 * @param addTrainingDataOptions the {@link AddTrainingDataOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link TrainingQuery}
 */
public ServiceCall<TrainingQuery> addTrainingData(AddTrainingDataOptions addTrainingDataOptions) {
    Validator.notNull(addTrainingDataOptions, "addTrainingDataOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "training_data" };
    String[] pathParameters = { addTrainingDataOptions.environmentId(), addTrainingDataOptions.collectionId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (addTrainingDataOptions.naturalLanguageQuery() != null) {
        contentJson.addProperty("natural_language_query", addTrainingDataOptions.naturalLanguageQuery());
    }
    if (addTrainingDataOptions.filter() != null) {
        contentJson.addProperty("filter", addTrainingDataOptions.filter());
    }
    if (addTrainingDataOptions.examples() != null) {
        contentJson.add("examples", GsonSingleton.getGson().toJsonTree(addTrainingDataOptions.examples()));
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingQuery.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) TrainingQuery(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery)

Aggregations

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