Search in sources :

Example 6 with TrainingExample

use of com.ibm.watson.discovery.v2.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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample) JsonObject(com.google.gson.JsonObject)

Example 7 with TrainingExample

use of com.ibm.watson.discovery.v2.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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample)

Example 8 with TrainingExample

use of com.ibm.watson.discovery.v2.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");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetTrainingExampleOptions(com.ibm.watson.discovery.v1.model.GetTrainingExampleOptions) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) Test(org.testng.annotations.Test)

Example 9 with TrainingExample

use of com.ibm.watson.discovery.v2.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");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CreateTrainingExampleOptions(com.ibm.watson.discovery.v1.model.CreateTrainingExampleOptions) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) Test(org.testng.annotations.Test)

Example 10 with TrainingExample

use of com.ibm.watson.discovery.v2.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");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UpdateTrainingExampleOptions(com.ibm.watson.discovery.v1.model.UpdateTrainingExampleOptions) TrainingExample(com.ibm.watson.discovery.v1.model.TrainingExample) Test(org.testng.annotations.Test)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)14 TrainingExample (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample)12 TrainingExample (com.ibm.watson.discovery.v1.model.TrainingExample)11 Test (org.junit.Test)9 TrainingQuery (com.ibm.watson.developer_cloud.discovery.v1.model.TrainingQuery)6 MockResponse (okhttp3.mockwebserver.MockResponse)6 Test (org.testng.annotations.Test)6 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)5 JsonObject (com.google.gson.JsonObject)4 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 AddTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddTrainingDataOptions)4 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 CreateTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateTrainingExampleOptions)3 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)3 HashMap (java.util.HashMap)3 GetTrainingDataOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingDataOptions)2 GetTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingExampleOptions)2 UpdateTrainingExampleOptions (com.ibm.watson.developer_cloud.discovery.v1.model.UpdateTrainingExampleOptions)2 AddTrainingDataOptions (com.ibm.watson.discovery.v1.model.AddTrainingDataOptions)2