use of com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method createTestQuery.
private TrainingQuery createTestQuery(String collectionId, String naturalLanguageQuery) {
AddTrainingDataOptions.Builder builder = new AddTrainingDataOptions.Builder(environmentId, collectionId);
builder.naturalLanguageQuery(naturalLanguageQuery);
TrainingQuery addResponse = discovery.addTrainingData(builder.build()).execute();
return addResponse;
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery in project java-sdk by watson-developer-cloud.
the class Discovery method getTrainingData.
/**
* Shows details for a specific training data query, including the query string and all examples.
*
* @param getTrainingDataOptions the {@link GetTrainingDataOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link TrainingQuery}
*/
public ServiceCall<TrainingQuery> getTrainingData(GetTrainingDataOptions getTrainingDataOptions) {
Validator.notNull(getTrainingDataOptions, "getTrainingDataOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "training_data" };
String[] pathParameters = { getTrainingDataOptions.environmentId(), getTrainingDataOptions.collectionId(), getTrainingDataOptions.queryId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingQuery.class));
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method getTrainingDataIsSuccessful.
@Test
public void getTrainingDataIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(getTrainingDataResp));
GetTrainingDataOptions.Builder builder = new GetTrainingDataOptions.Builder(environmentId, collectionId, queryId);
TrainingQuery response = discoveryService.getTrainingData(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(TRAINING3_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(getTrainingDataResp, response);
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method addTrainingDataIsSuccessful.
// Training data tests
@Test
public void addTrainingDataIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(addTrainingQueryResp));
AddTrainingDataOptions.Builder builder = new AddTrainingDataOptions.Builder(environmentId, collectionId);
builder.naturalLanguageQuery("Example query");
TrainingExample example = new TrainingExample();
example.setDocumentId(documentId);
example.setRelevance(0);
builder.addExamples(example);
TrainingQuery response = discoveryService.addTrainingData(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(TRAINING1_PATH, request.getPath());
assertEquals(POST, request.getMethod());
assertEquals(addTrainingQueryResp, response);
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method addTrainingDataIsSuccessful.
@Test
public void addTrainingDataIsSuccessful() {
AddTrainingDataOptions.Builder builder = new AddTrainingDataOptions.Builder(environmentId, collectionId);
String naturalLanguageQuery = "Example query" + UUID.randomUUID().toString();
builder.naturalLanguageQuery(naturalLanguageQuery);
TrainingExample example = new TrainingExample();
String documentId = createTestDocument("test_document", collectionId).getDocumentId();
example.setDocumentId(documentId);
int relevance = 0;
example.setRelevance(relevance);
builder.addExamples(example);
TrainingQuery response = discovery.addTrainingData(builder.build()).execute();
assertFalse(response.getQueryId().isEmpty());
assertEquals(response.getNaturalLanguageQuery(), naturalLanguageQuery);
assertTrue(response.getFilter().isEmpty());
assertEquals(response.getExamples().size(), 1);
TrainingExample returnedExample = response.getExamples().get(0);
assertEquals(returnedExample.getDocumentId(), documentId);
assertTrue(returnedExample.getCrossReference().isEmpty());
assertEquals(returnedExample.getRelevance(), new Long(relevance));
}
Aggregations