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