Search in sources :

Example 1 with TrainingExample

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

the class DiscoveryServiceIT method addTrainingExampleIsSuccessful.

@Test
public void addTrainingExampleIsSuccessful() {
    TrainingQuery query = createTestQuery(collectionId, "Query" + UUID.randomUUID().toString());
    int startingExampleCount = query.getExamples().size();
    String queryId = query.getQueryId();
    String documentId = "document_id";
    String crossReference = "cross_reference";
    int relevance = 50;
    CreateTrainingExampleOptions.Builder exampleBuilder = new CreateTrainingExampleOptions.Builder(environmentId, collectionId, queryId);
    exampleBuilder.documentId(documentId);
    exampleBuilder.crossReference(crossReference);
    exampleBuilder.relevance(relevance);
    discovery.createTrainingExample(exampleBuilder.build()).execute();
    GetTrainingDataOptions.Builder queryBuilder = new GetTrainingDataOptions.Builder(environmentId, collectionId, queryId);
    TrainingQuery updatedQuery = discovery.getTrainingData(queryBuilder.build()).execute();
    assertTrue(updatedQuery.getExamples().size() > startingExampleCount);
    TrainingExample newExample = updatedQuery.getExamples().get(0);
    assertEquals(newExample.getDocumentId(), documentId);
    assertEquals(newExample.getCrossReference(), crossReference);
    assertEquals(newExample.getRelevance(), new Long(relevance));
}
Also used : CreateTrainingExampleOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateTrainingExampleOptions) GetTrainingDataOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingDataOptions) 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)

Example 2 with TrainingExample

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

the class DiscoveryServiceIT method getTrainingExampleIsSuccessful.

@Test
public void getTrainingExampleIsSuccessful() {
    AddTrainingDataOptions.Builder builder = new AddTrainingDataOptions.Builder(environmentId, collectionId);
    String naturalLanguageQuery = "Query" + UUID.randomUUID().toString();
    builder.naturalLanguageQuery(naturalLanguageQuery);
    TrainingExample example = new TrainingExample();
    String documentId = "Document" + UUID.randomUUID().toString();
    example.setDocumentId(documentId);
    int relevance = 0;
    example.setRelevance(relevance);
    builder.addExamples(example);
    TrainingQuery response = discovery.addTrainingData(builder.build()).execute();
    String queryId = response.getQueryId();
    GetTrainingExampleOptions.Builder getExampleBuilder = new GetTrainingExampleOptions.Builder(environmentId, collectionId, queryId, documentId);
    TrainingExample returnedExample = discovery.getTrainingExample(getExampleBuilder.build()).execute();
    assertEquals(returnedExample.getDocumentId(), documentId);
}
Also used : AddTrainingDataOptions(com.ibm.watson.developer_cloud.discovery.v1.model.AddTrainingDataOptions) GetTrainingExampleOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingExampleOptions) 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)

Example 3 with TrainingExample

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

the class DiscoveryServiceTest method getTrainingExampleIsSuccessful.

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

Example 4 with TrainingExample

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

the class DiscoveryServiceTest method createTrainingExampleIsSuccessful.

@Test
public void createTrainingExampleIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(createTrainingExampleResp));
    CreateTrainingExampleOptions.Builder builder = new CreateTrainingExampleOptions.Builder(environmentId, collectionId, queryId);
    builder.documentId(documentId);
    builder.relevance(0);
    TrainingExample response = discoveryService.createTrainingExample(builder.build()).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(TRAINING2_PATH, request.getPath());
    assertEquals(POST, request.getMethod());
    assertEquals(createTrainingExampleResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) CreateTrainingExampleOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateTrainingExampleOptions) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 5 with TrainingExample

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

the class DiscoveryServiceIT method updateTrainingExampleIsSuccessful.

@Test
public void updateTrainingExampleIsSuccessful() {
    AddTrainingDataOptions.Builder builder = new AddTrainingDataOptions.Builder(environmentId, collectionId);
    String naturalLanguageQuery = "Query" + UUID.randomUUID().toString();
    builder.naturalLanguageQuery(naturalLanguageQuery);
    TrainingExample example = new TrainingExample();
    String documentId = "Document" + UUID.randomUUID().toString();
    example.setDocumentId(documentId);
    int relevance = 0;
    example.setRelevance(relevance);
    builder.addExamples(example);
    TrainingQuery response = discovery.addTrainingData(builder.build()).execute();
    String queryId = response.getQueryId();
    UpdateTrainingExampleOptions.Builder updateBuilder = new UpdateTrainingExampleOptions.Builder(environmentId, collectionId, queryId, documentId);
    String newCrossReference = "cross_reference";
    updateBuilder.crossReference(newCrossReference);
    int newRelevance = 50;
    updateBuilder.relevance(newRelevance);
    TrainingExample updatedExample = discovery.updateTrainingExample(updateBuilder.build()).execute();
    assertEquals(updatedExample.getCrossReference(), newCrossReference);
    assertEquals(updatedExample.getRelevance(), new Long(newRelevance));
}
Also used : AddTrainingDataOptions(com.ibm.watson.developer_cloud.discovery.v1.model.AddTrainingDataOptions) UpdateTrainingExampleOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateTrainingExampleOptions) 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

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