use of com.ibm.watson.discovery.v1.model.TrainingExample in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method addTrainingDataIsSuccessful.
/**
* Adds the training data is successful.
*
* @throws InterruptedException the interrupted exception
*/
// 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.Builder().documentId(documentId).relevance(0).build();
builder.addExamples(example);
TrainingQuery response = discoveryService.addTrainingData(builder.build()).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(TRAINING1_PATH, request.getPath());
assertEquals(POST, request.getMethod());
assertEquals(addTrainingQueryResp, response);
}
use of com.ibm.watson.discovery.v1.model.TrainingExample in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method getTrainingExampleIsSuccessful.
/**
* Gets the training example is successful.
*
* @throws InterruptedException the interrupted exception
*/
@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().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(TRAINING4_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(getTrainingExampleResp, response);
}
use of com.ibm.watson.discovery.v1.model.TrainingExample in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method updateTrainingExampleIsSuccessful.
/**
* Update training example is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void updateTrainingExampleIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(updateTrainingExampleResp));
UpdateTrainingExampleOptions.Builder builder = new UpdateTrainingExampleOptions.Builder(environmentId, collectionId, queryId, documentId);
builder.relevance(100);
TrainingExample response = discoveryService.updateTrainingExample(builder.build()).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(TRAINING4_PATH, request.getPath());
assertEquals(PUT, request.getMethod());
assertEquals(updateTrainingExampleResp, response);
}
use of com.ibm.watson.discovery.v1.model.TrainingExample in project java-sdk by watson-developer-cloud.
the class Discovery method createTrainingExample.
/**
* Add example to training data query.
*
* <p>Adds a example to this training data query.
*
* @param createTrainingExampleOptions the {@link CreateTrainingExampleOptions} containing the
* options for the call
* @return a {@link ServiceCall} with a result of type {@link TrainingExample}
*/
public ServiceCall<TrainingExample> createTrainingExample(CreateTrainingExampleOptions createTrainingExampleOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createTrainingExampleOptions, "createTrainingExampleOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", createTrainingExampleOptions.environmentId());
pathParamsMap.put("collection_id", createTrainingExampleOptions.collectionId());
pathParamsMap.put("query_id", createTrainingExampleOptions.queryId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/training_data/{query_id}/examples", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createTrainingExample");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
final JsonObject contentJson = new JsonObject();
if (createTrainingExampleOptions.documentId() != null) {
contentJson.addProperty("document_id", createTrainingExampleOptions.documentId());
}
if (createTrainingExampleOptions.crossReference() != null) {
contentJson.addProperty("cross_reference", createTrainingExampleOptions.crossReference());
}
if (createTrainingExampleOptions.relevance() != null) {
contentJson.addProperty("relevance", createTrainingExampleOptions.relevance());
}
builder.bodyJson(contentJson);
ResponseConverter<TrainingExample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingExample>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.TrainingExample in project java-sdk by watson-developer-cloud.
the class Discovery method getTrainingExample.
/**
* Get details for training data example.
*
* <p>Gets the details for this training example.
*
* @param getTrainingExampleOptions the {@link GetTrainingExampleOptions} containing the options
* for the call
* @return a {@link ServiceCall} with a result of type {@link TrainingExample}
*/
public ServiceCall<TrainingExample> getTrainingExample(GetTrainingExampleOptions getTrainingExampleOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getTrainingExampleOptions, "getTrainingExampleOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", getTrainingExampleOptions.environmentId());
pathParamsMap.put("collection_id", getTrainingExampleOptions.collectionId());
pathParamsMap.put("query_id", getTrainingExampleOptions.queryId());
pathParamsMap.put("example_id", getTrainingExampleOptions.exampleId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/training_data/{query_id}/examples/{example_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getTrainingExample");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
ResponseConverter<TrainingExample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TrainingExample>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations