use of com.ibm.watson.discovery.v1.model.TrainingExample in project java-sdk by watson-developer-cloud.
the class Discovery method updateTrainingExample.
/**
* Changes the label or cross reference query for this training example.
*
* @param updateTrainingExampleOptions the {@link UpdateTrainingExampleOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link TrainingExample}
*/
public ServiceCall<TrainingExample> updateTrainingExample(UpdateTrainingExampleOptions updateTrainingExampleOptions) {
Validator.notNull(updateTrainingExampleOptions, "updateTrainingExampleOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "training_data", "examples" };
String[] pathParameters = { updateTrainingExampleOptions.environmentId(), updateTrainingExampleOptions.collectionId(), updateTrainingExampleOptions.queryId(), updateTrainingExampleOptions.exampleId() };
RequestBuilder builder = RequestBuilder.put(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (updateTrainingExampleOptions.crossReference() != null) {
contentJson.addProperty("cross_reference", updateTrainingExampleOptions.crossReference());
}
if (updateTrainingExampleOptions.relevance() != null) {
contentJson.addProperty("relevance", updateTrainingExampleOptions.relevance());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingExample.class));
}
use of com.ibm.watson.discovery.v1.model.TrainingExample in project java-sdk by watson-developer-cloud.
the class Discovery method getTrainingExample.
/**
* Gets the details for this training example.
*
* @param getTrainingExampleOptions the {@link GetTrainingExampleOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link TrainingExample}
*/
public ServiceCall<TrainingExample> getTrainingExample(GetTrainingExampleOptions getTrainingExampleOptions) {
Validator.notNull(getTrainingExampleOptions, "getTrainingExampleOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "training_data", "examples" };
String[] pathParameters = { getTrainingExampleOptions.environmentId(), getTrainingExampleOptions.collectionId(), getTrainingExampleOptions.queryId(), getTrainingExampleOptions.exampleId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TrainingExample.class));
}
use of com.ibm.watson.discovery.v1.model.TrainingExample in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testGetTrainingExampleWOptions.
// Test the getTrainingExample operation with a valid options model parameter
@Test
public void testGetTrainingExampleWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"document_id\": \"documentId\", \"cross_reference\": \"crossReference\", \"relevance\": 9}";
String getTrainingExamplePath = "/v1/environments/testString/collections/testString/training_data/testString/examples/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the GetTrainingExampleOptions model
GetTrainingExampleOptions getTrainingExampleOptionsModel = new GetTrainingExampleOptions.Builder().environmentId("testString").collectionId("testString").queryId("testString").exampleId("testString").build();
// Invoke getTrainingExample() with a valid options model and verify the result
Response<TrainingExample> response = discoveryService.getTrainingExample(getTrainingExampleOptionsModel).execute();
assertNotNull(response);
TrainingExample responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getTrainingExamplePath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
}
use of com.ibm.watson.discovery.v1.model.TrainingExample in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testCreateTrainingExampleWOptions.
// Test the createTrainingExample operation with a valid options model parameter
@Test
public void testCreateTrainingExampleWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"document_id\": \"documentId\", \"cross_reference\": \"crossReference\", \"relevance\": 9}";
String createTrainingExamplePath = "/v1/environments/testString/collections/testString/training_data/testString/examples";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
// Construct an instance of the CreateTrainingExampleOptions model
CreateTrainingExampleOptions createTrainingExampleOptionsModel = new CreateTrainingExampleOptions.Builder().environmentId("testString").collectionId("testString").queryId("testString").documentId("testString").crossReference("testString").relevance(Long.valueOf("26")).build();
// Invoke createTrainingExample() with a valid options model and verify the result
Response<TrainingExample> response = discoveryService.createTrainingExample(createTrainingExampleOptionsModel).execute();
assertNotNull(response);
TrainingExample responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, createTrainingExamplePath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
}
use of com.ibm.watson.discovery.v1.model.TrainingExample in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testUpdateTrainingExampleWOptions.
// Test the updateTrainingExample operation with a valid options model parameter
@Test
public void testUpdateTrainingExampleWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"document_id\": \"documentId\", \"cross_reference\": \"crossReference\", \"relevance\": 9}";
String updateTrainingExamplePath = "/v1/environments/testString/collections/testString/training_data/testString/examples/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the UpdateTrainingExampleOptions model
UpdateTrainingExampleOptions updateTrainingExampleOptionsModel = new UpdateTrainingExampleOptions.Builder().environmentId("testString").collectionId("testString").queryId("testString").exampleId("testString").crossReference("testString").relevance(Long.valueOf("26")).build();
// Invoke updateTrainingExample() with a valid options model and verify the result
Response<TrainingExample> response = discoveryService.updateTrainingExample(updateTrainingExampleOptionsModel).execute();
assertNotNull(response);
TrainingExample responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "PUT");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, updateTrainingExamplePath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
}
Aggregations