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));
}
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);
}
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);
}
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);
}
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));
}
Aggregations