Search in sources :

Example 11 with TrainingExample

use of com.ibm.watson.discovery.v2.model.TrainingExample in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method addTrainingDataIsSuccessful.

/**
 * Adds the training data is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
// Training data tests
@Test
public void addTrainingDataIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(addTrainingQueryResp));
    AddTrainingDataOptions.Builder builder = new AddTrainingDataOptions.Builder(environmentId, collectionId);
    builder.naturalLanguageQuery("Example query");
    TrainingExample example = new TrainingExample.Builder().documentId(documentId).relevance(0).build();
    builder.addExamples(example);
    TrainingQuery response = discoveryService.addTrainingData(builder.build()).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(TRAINING1_PATH, request.getPath());
    assertEquals(POST, request.getMethod());
    assertEquals(addTrainingQueryResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) AddTrainingDataOptions(com.ibm.watson.discovery.v1.model.AddTrainingDataOptions) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) TrainingQuery(com.ibm.watson.discovery.v1.model.TrainingQuery) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 12 with TrainingExample

use of com.ibm.watson.discovery.v2.model.TrainingExample in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method getTrainingExampleIsSuccessful.

/**
 * Gets the training example is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getTrainingExampleIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(getTrainingExampleResp));
    GetTrainingExampleOptions.Builder builder = new GetTrainingExampleOptions.Builder(environmentId, collectionId, queryId, documentId);
    TrainingExample response = discoveryService.getTrainingExample(builder.build()).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(TRAINING4_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(getTrainingExampleResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetTrainingExampleOptions(com.ibm.watson.discovery.v1.model.GetTrainingExampleOptions) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 13 with TrainingExample

use of com.ibm.watson.discovery.v2.model.TrainingExample in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method updateTrainingExampleIsSuccessful.

/**
 * Update training example is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void updateTrainingExampleIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(updateTrainingExampleResp));
    UpdateTrainingExampleOptions.Builder builder = new UpdateTrainingExampleOptions.Builder(environmentId, collectionId, queryId, documentId);
    builder.relevance(100);
    TrainingExample response = discoveryService.updateTrainingExample(builder.build()).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(TRAINING4_PATH, request.getPath());
    assertEquals(PUT, request.getMethod());
    assertEquals(updateTrainingExampleResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) UpdateTrainingExampleOptions(com.ibm.watson.discovery.v1.model.UpdateTrainingExampleOptions) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 14 with TrainingExample

use of com.ibm.watson.discovery.v2.model.TrainingExample in project java-sdk by watson-developer-cloud.

the class Discovery method createTrainingExample.

/**
 * Add example to training data query.
 *
 * <p>Adds a example to this training data query.
 *
 * @param createTrainingExampleOptions the {@link CreateTrainingExampleOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link TrainingExample}
 */
public ServiceCall<TrainingExample> createTrainingExample(CreateTrainingExampleOptions createTrainingExampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createTrainingExampleOptions, "createTrainingExampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", createTrainingExampleOptions.environmentId());
    pathParamsMap.put("collection_id", createTrainingExampleOptions.collectionId());
    pathParamsMap.put("query_id", createTrainingExampleOptions.queryId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/training_data/{query_id}/examples", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createTrainingExample");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    if (createTrainingExampleOptions.documentId() != null) {
        contentJson.addProperty("document_id", createTrainingExampleOptions.documentId());
    }
    if (createTrainingExampleOptions.crossReference() != null) {
        contentJson.addProperty("cross_reference", createTrainingExampleOptions.crossReference());
    }
    if (createTrainingExampleOptions.relevance() != null) {
        contentJson.addProperty("relevance", createTrainingExampleOptions.relevance());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<TrainingExample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingExample>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) JsonObject(com.google.gson.JsonObject)

Example 15 with TrainingExample

use of com.ibm.watson.discovery.v2.model.TrainingExample in project java-sdk by watson-developer-cloud.

the class Discovery method getTrainingExample.

/**
 * Get details for training data example.
 *
 * <p>Gets the details for this training example.
 *
 * @param getTrainingExampleOptions the {@link GetTrainingExampleOptions} containing the options
 *     for the call
 * @return a {@link ServiceCall} with a result of type {@link TrainingExample}
 */
public ServiceCall<TrainingExample> getTrainingExample(GetTrainingExampleOptions getTrainingExampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getTrainingExampleOptions, "getTrainingExampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", getTrainingExampleOptions.environmentId());
    pathParamsMap.put("collection_id", getTrainingExampleOptions.collectionId());
    pathParamsMap.put("query_id", getTrainingExampleOptions.queryId());
    pathParamsMap.put("example_id", getTrainingExampleOptions.exampleId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/training_data/{query_id}/examples/{example_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getTrainingExample");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<TrainingExample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingExample>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)14 TrainingExample (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample)12 TrainingExample (com.ibm.watson.discovery.v1.model.TrainingExample)11 Test (org.junit.Test)9 TrainingQuery (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery)6 MockResponse (okhttp3.mockwebserver.MockResponse)6 Test (org.testng.annotations.Test)6 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)5 JsonObject (com.google.gson.JsonObject)4 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 AddTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddTrainingDataOptions)4 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 CreateTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateTrainingExampleOptions)3 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)3 HashMap (java.util.HashMap)3 GetTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingDataOptions)2 GetTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingExampleOptions)2 UpdateTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.UpdateTrainingExampleOptions)2 AddTrainingDataOptions (com.ibm.watson.discovery.v1.model.AddTrainingDataOptions)2