Search in sources :

Example 1 with TrainingQuery

use of com.ibm.watson.discovery.v1.model.TrainingQuery 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 TrainingQuery

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

the class DiscoveryServiceIT method deleteTrainingDataQueryIsSuccessful.

@Test
public void deleteTrainingDataQueryIsSuccessful() {
    TrainingQuery query = createTestQuery(collectionId, "Query" + UUID.randomUUID().toString());
    String queryId = query.getQueryId();
    ListTrainingDataOptions.Builder listBuilder = new ListTrainingDataOptions.Builder(environmentId, collectionId);
    TrainingDataSet trainingData = discovery.listTrainingData(listBuilder.build()).execute();
    List<TrainingQuery> queryList = trainingData.getQueries();
    boolean doesQueryExist = false;
    for (TrainingQuery q : queryList) {
        if (q.getQueryId().equals(queryId)) {
            doesQueryExist = true;
            break;
        }
    }
    assertTrue(doesQueryExist);
    DeleteTrainingDataOptions.Builder deleteBuilder = new DeleteTrainingDataOptions.Builder(environmentId, collectionId, queryId);
    discovery.deleteTrainingData(deleteBuilder.build()).execute();
    listBuilder = new ListTrainingDataOptions.Builder(environmentId, collectionId);
    trainingData = discovery.listTrainingData(listBuilder.build()).execute();
    queryList = trainingData.getQueries();
    doesQueryExist = false;
    for (TrainingQuery q : queryList) {
        if (q.getQueryId().equals(queryId)) {
            doesQueryExist = true;
            break;
        }
    }
    assertFalse(doesQueryExist);
}
Also used : ListTrainingDataOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListTrainingDataOptions) TrainingDataSet(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingDataSet) DeleteTrainingDataOptions(com.ibm.watson.developer_cloud.discovery.v1.model.DeleteTrainingDataOptions) TrainingQuery(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 3 with TrainingQuery

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

the class DiscoveryServiceIT method getTrainingDataIsSuccessful.

@Test
public void getTrainingDataIsSuccessful() {
    String naturalLanguageQuery = "Query" + UUID.randomUUID().toString();
    TrainingQuery newQuery = createTestQuery(collectionId, naturalLanguageQuery);
    String queryId = newQuery.getQueryId();
    GetTrainingDataOptions.Builder queryBuilder = new GetTrainingDataOptions.Builder(environmentId, collectionId, queryId);
    TrainingQuery queryResponse = discovery.getTrainingData(queryBuilder.build()).execute();
    assertEquals(queryResponse.getNaturalLanguageQuery(), naturalLanguageQuery);
}
Also used : GetTrainingDataOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingDataOptions) TrainingQuery(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 4 with TrainingQuery

use of com.ibm.watson.discovery.v1.model.TrainingQuery 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 5 with TrainingQuery

use of com.ibm.watson.discovery.v1.model.TrainingQuery 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

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