Search in sources :

Example 1 with Counterexample

use of com.ibm.watson.assistant.v1.model.Counterexample in project java-sdk by watson-developer-cloud.

the class Conversation method getCounterexample.

/**
 * Get counterexample.
 *
 * Get information about a counterexample. Counterexamples are examples that have been marked as irrelevant input.
 *
 * @param getCounterexampleOptions the {@link GetCounterexampleOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Counterexample}
 */
public ServiceCall<Counterexample> getCounterexample(GetCounterexampleOptions getCounterexampleOptions) {
    Validator.notNull(getCounterexampleOptions, "getCounterexampleOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "counterexamples" };
    String[] pathParameters = { getCounterexampleOptions.workspaceId(), getCounterexampleOptions.text() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (getCounterexampleOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getCounterexampleOptions.includeAudit()));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Counterexample.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Counterexample(com.ibm.watson.developer_cloud.conversation.v1.model.Counterexample)

Example 2 with Counterexample

use of com.ibm.watson.assistant.v1.model.Counterexample in project java-sdk by watson-developer-cloud.

the class Conversation method createCounterexample.

/**
 * Create counterexample.
 *
 * Add a new counterexample to a workspace. Counterexamples are examples that have been marked as irrelevant input.
 *
 * @param createCounterexampleOptions the {@link CreateCounterexampleOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Counterexample}
 */
public ServiceCall<Counterexample> createCounterexample(CreateCounterexampleOptions createCounterexampleOptions) {
    Validator.notNull(createCounterexampleOptions, "createCounterexampleOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "counterexamples" };
    String[] pathParameters = { createCounterexampleOptions.workspaceId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("text", createCounterexampleOptions.text());
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Counterexample.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Counterexample(com.ibm.watson.developer_cloud.conversation.v1.model.Counterexample)

Example 3 with Counterexample

use of com.ibm.watson.assistant.v1.model.Counterexample in project java-sdk by watson-developer-cloud.

the class AssistantServiceIT method testCreateCounterexample.

/**
 * Test createCounterexample.
 */
@Test
public void testCreateCounterexample() {
    // gotta be unique
    String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    Counterexample response = service.createCounterexample(createOptions).execute();
    try {
        assertNotNull(response);
        assertNotNull(response.getText());
        assertEquals(response.getText(), counterExampleText);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
        service.deleteCounterexample(deleteOptions).execute();
    }
}
Also used : CreateCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions) DeleteCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteCounterexampleOptions) Counterexample(com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample) CreateCounterexample(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 4 with Counterexample

use of com.ibm.watson.assistant.v1.model.Counterexample in project java-sdk by watson-developer-cloud.

the class AssistantServiceIT method testGetCounterexample.

/**
 * Test getCounterexample.
 */
@Test
public void testGetCounterexample() {
    Date start = new Date();
    // gotta be unique
    String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    service.createCounterexample(createOptions).execute();
    try {
        GetCounterexampleOptions getOptions = new GetCounterexampleOptions.Builder(workspaceId, counterExampleText).includeAudit(true).build();
        Counterexample response = service.getCounterexample(getOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getText());
        assertEquals(response.getText(), counterExampleText);
        assertNotNull(response.getCreated());
        assertNotNull(response.getUpdated());
        Date now = new Date();
        assertTrue(fuzzyBefore(response.getCreated(), now));
        assertTrue(fuzzyAfter(response.getCreated(), start));
        assertTrue(fuzzyBefore(response.getUpdated(), now));
        assertTrue(fuzzyAfter(response.getUpdated(), start));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
        service.deleteCounterexample(deleteOptions).execute();
    }
}
Also used : CreateCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions) DeleteCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteCounterexampleOptions) GetCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetCounterexampleOptions) Counterexample(com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample) CreateCounterexample(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample) Date(java.util.Date) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 5 with Counterexample

use of com.ibm.watson.assistant.v1.model.Counterexample in project java-sdk by watson-developer-cloud.

the class AssistantServiceIT method testListCounterexamples.

/**
 * Test listCounterexamples.
 */
@Test
public void testListCounterexamples() {
    // gotta be unique
    String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    try {
        ListCounterexamplesOptions listOptions = new ListCounterexamplesOptions.Builder(workspaceId).build();
        CounterexampleCollection ccResponse = service.listCounterexamples(listOptions).execute();
        assertNotNull(ccResponse);
        assertNotNull(ccResponse.getCounterexamples());
        assertNotNull(ccResponse.getPagination());
        assertNotNull(ccResponse.getPagination().getRefreshUrl());
        // nextUrl may be null
        Date start = new Date();
        // Now add a counterexample and make sure we get it back
        CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
        service.createCounterexample(createOptions).execute();
        long count = ccResponse.getCounterexamples().size();
        CounterexampleCollection ccResponse2 = service.listCounterexamples(listOptions.newBuilder().pageLimit(count + 1).includeAudit(true).build()).execute();
        assertNotNull(ccResponse2);
        assertNotNull(ccResponse2.getCounterexamples());
        List<Counterexample> counterexamples = ccResponse2.getCounterexamples();
        assertTrue(counterexamples.size() > count);
        Counterexample exResponse = null;
        for (Counterexample resp : counterexamples) {
            if (resp.getText().equals(counterExampleText)) {
                exResponse = resp;
                break;
            }
        }
        assertNotNull(exResponse);
        Date now = new Date();
        assertTrue(fuzzyBefore(exResponse.getCreated(), now));
        assertTrue(fuzzyAfter(exResponse.getCreated(), start));
        assertTrue(fuzzyBefore(exResponse.getUpdated(), now));
        assertTrue(fuzzyAfter(exResponse.getUpdated(), start));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        try {
            DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
            service.deleteCounterexample(deleteOptions).execute();
        } catch (NotFoundException ex) {
        // Okay
        }
    }
}
Also used : ListCounterexamplesOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListCounterexamplesOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) DeleteCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteCounterexampleOptions) Counterexample(com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample) CreateCounterexample(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample) Date(java.util.Date) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) CounterexampleCollection(com.ibm.watson.developer_cloud.assistant.v1.model.CounterexampleCollection) CreateCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions) Test(org.junit.Test)

Aggregations

NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)10 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)10 Test (org.junit.Test)10 Counterexample (com.ibm.watson.assistant.v1.model.Counterexample)8 Counterexample (com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample)8 Counterexample (com.ibm.watson.developer_cloud.conversation.v1.model.Counterexample)8 JsonObject (com.google.gson.JsonObject)6 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)6 CreateCounterexample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample)5 CreateCounterexample (com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexample)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 Test (org.testng.annotations.Test)5 CreateCounterexampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexampleOptions)4 DeleteCounterexampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteCounterexampleOptions)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 CreateCounterexampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions)3 DeleteCounterexampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteCounterexampleOptions)3