Search in sources :

Example 6 with TrainingExample

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

the class Discovery method updateTrainingExample.

/**
 * Changes the label or cross reference query for this training example.
 *
 * @param updateTrainingExampleOptions the {@link UpdateTrainingExampleOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link TrainingExample}
 */
public ServiceCall<TrainingExample> updateTrainingExample(UpdateTrainingExampleOptions updateTrainingExampleOptions) {
    Validator.notNull(updateTrainingExampleOptions, "updateTrainingExampleOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "training_data", "examples" };
    String[] pathParameters = { updateTrainingExampleOptions.environmentId(), updateTrainingExampleOptions.collectionId(), updateTrainingExampleOptions.queryId(), updateTrainingExampleOptions.exampleId() };
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (updateTrainingExampleOptions.crossReference() != null) {
        contentJson.addProperty("cross_reference", updateTrainingExampleOptions.crossReference());
    }
    if (updateTrainingExampleOptions.relevance() != null) {
        contentJson.addProperty("relevance", updateTrainingExampleOptions.relevance());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingExample.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample) JsonObject(com.google.gson.JsonObject)

Example 7 with TrainingExample

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

the class Discovery method getTrainingExample.

/**
 * Gets the details for this training example.
 *
 * @param getTrainingExampleOptions the {@link GetTrainingExampleOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link TrainingExample}
 */
public ServiceCall<TrainingExample> getTrainingExample(GetTrainingExampleOptions getTrainingExampleOptions) {
    Validator.notNull(getTrainingExampleOptions, "getTrainingExampleOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "training_data", "examples" };
    String[] pathParameters = { getTrainingExampleOptions.environmentId(), getTrainingExampleOptions.collectionId(), getTrainingExampleOptions.queryId(), getTrainingExampleOptions.exampleId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingExample.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample)

Example 8 with TrainingExample

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

the class DiscoveryServiceTest method addTrainingDataIsSuccessful.

// 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();
    example.setDocumentId(documentId);
    example.setRelevance(0);
    builder.addExamples(example);
    TrainingQuery response = discoveryService.addTrainingData(builder.build()).execute();
    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.developer_cloud.discovery.v1.model.AddTrainingDataOptions) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample) TrainingQuery(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 9 with TrainingExample

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

the class DiscoveryServiceTest method updateTrainingExampleIsSuccessful.

@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();
    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.developer_cloud.discovery.v1.model.UpdateTrainingExampleOptions) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 10 with TrainingExample

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

the class DiscoveryServiceIT method addTrainingDataIsSuccessful.

@Test
public void addTrainingDataIsSuccessful() {
    AddTrainingDataOptions.Builder builder = new AddTrainingDataOptions.Builder(environmentId, collectionId);
    String naturalLanguageQuery = "Example query" + UUID.randomUUID().toString();
    builder.naturalLanguageQuery(naturalLanguageQuery);
    TrainingExample example = new TrainingExample();
    String documentId = createTestDocument("test_document", collectionId).getDocumentId();
    example.setDocumentId(documentId);
    int relevance = 0;
    example.setRelevance(relevance);
    builder.addExamples(example);
    TrainingQuery response = discovery.addTrainingData(builder.build()).execute();
    assertFalse(response.getQueryId().isEmpty());
    assertEquals(response.getNaturalLanguageQuery(), naturalLanguageQuery);
    assertTrue(response.getFilter().isEmpty());
    assertEquals(response.getExamples().size(), 1);
    TrainingExample returnedExample = response.getExamples().get(0);
    assertEquals(returnedExample.getDocumentId(), documentId);
    assertTrue(returnedExample.getCrossReference().isEmpty());
    assertEquals(returnedExample.getRelevance(), new Long(relevance));
}
Also used : AddTrainingDataOptions(com.ibm.watson.developer_cloud.discovery.v1.model.AddTrainingDataOptions) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample) TrainingQuery(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

TrainingExample (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample)12 Test (org.junit.Test)9 TrainingQuery (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery)6 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)5 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 AddTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddTrainingDataOptions)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 CreateTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateTrainingExampleOptions)3 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)3 JsonObject (com.google.gson.JsonObject)2 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 DeleteTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteTrainingExampleOptions)1