use of com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method deleteTrainingDataExampleIsSuccessful.
@Test
public void deleteTrainingDataExampleIsSuccessful() {
TrainingQuery newQuery = createTestQuery(collectionId, "Query" + UUID.randomUUID().toString());
String queryId = newQuery.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);
TrainingExample createdExample = discovery.createTrainingExample(exampleBuilder.build()).execute();
String exampleId = createdExample.getDocumentId();
GetTrainingDataOptions.Builder queryBuilder = new GetTrainingDataOptions.Builder(environmentId, collectionId, queryId);
TrainingQuery queryWithAddedExample = discovery.getTrainingData(queryBuilder.build()).execute();
int startingCount = queryWithAddedExample.getExamples().size();
DeleteTrainingExampleOptions.Builder deleteBuilder = new DeleteTrainingExampleOptions.Builder(environmentId, collectionId, queryId, exampleId);
discovery.deleteTrainingExample(deleteBuilder.build()).execute();
GetTrainingDataOptions.Builder newQueryBuilder = new GetTrainingDataOptions.Builder(environmentId, collectionId, queryId);
TrainingQuery queryWithDeletedExample = discovery.getTrainingData(newQueryBuilder.build()).execute();
assertTrue(startingCount > queryWithDeletedExample.getExamples().size());
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery in project java-sdk by watson-developer-cloud.
the class Discovery method addTrainingData.
/**
* Adds a query to the training data for this collection. The query can contain a filter and natural language query.
*
* @param addTrainingDataOptions the {@link AddTrainingDataOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link TrainingQuery}
*/
public ServiceCall<TrainingQuery> addTrainingData(AddTrainingDataOptions addTrainingDataOptions) {
Validator.notNull(addTrainingDataOptions, "addTrainingDataOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "training_data" };
String[] pathParameters = { addTrainingDataOptions.environmentId(), addTrainingDataOptions.collectionId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (addTrainingDataOptions.naturalLanguageQuery() != null) {
contentJson.addProperty("natural_language_query", addTrainingDataOptions.naturalLanguageQuery());
}
if (addTrainingDataOptions.filter() != null) {
contentJson.addProperty("filter", addTrainingDataOptions.filter());
}
if (addTrainingDataOptions.examples() != null) {
contentJson.add("examples", GsonSingleton.getGson().toJsonTree(addTrainingDataOptions.examples()));
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingQuery.class));
}
Aggregations