Search in sources :

Example 1 with GetCounterexampleOptions

use of com.ibm.watson.developer_cloud.conversation.v1.model.GetCounterexampleOptions 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 GetCounterexampleOptions

use of com.ibm.watson.developer_cloud.conversation.v1.model.GetCounterexampleOptions 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 3 with GetCounterexampleOptions

use of com.ibm.watson.developer_cloud.conversation.v1.model.GetCounterexampleOptions in project java-sdk by watson-developer-cloud.

the class ConversationServiceIT method testDeleteCounterexample.

/**
 * Test deleteCounterexample.
 */
@Test
public void testDeleteCounterexample() {
    // gotta be unique
    String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    service.createCounterexample(createOptions).execute();
    DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    service.deleteCounterexample(deleteOptions).execute();
    try {
        GetCounterexampleOptions getOptions = new GetCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
        service.getCounterexample(getOptions).execute();
        fail("deleteCounterexample failed");
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
    }
}
Also used : CreateCounterexampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexampleOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) DeleteCounterexampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteCounterexampleOptions) GetCounterexampleOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetCounterexampleOptions) 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 GetCounterexampleOptions

use of com.ibm.watson.developer_cloud.conversation.v1.model.GetCounterexampleOptions in project java-sdk by watson-developer-cloud.

the class AssistantServiceIT method testDeleteCounterexample.

/**
 * Test deleteCounterexample.
 */
@Test
public void testDeleteCounterexample() {
    // gotta be unique
    String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    service.createCounterexample(createOptions).execute();
    DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    service.deleteCounterexample(deleteOptions).execute();
    try {
        GetCounterexampleOptions getOptions = new GetCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
        service.getCounterexample(getOptions).execute();
        fail("deleteCounterexample failed");
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
    }
}
Also used : CreateCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) DeleteCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteCounterexampleOptions) GetCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetCounterexampleOptions) 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 GetCounterexampleOptions

use of com.ibm.watson.developer_cloud.conversation.v1.model.GetCounterexampleOptions in project java-sdk by watson-developer-cloud.

the class AssistantServiceIT method testUpdateWorkspace.

/**
 * Test updateWorkspace.
 */
@Test
public void testUpdateWorkspace() {
    String workspaceName = "testUpdateWorkspace";
    String workspaceDescription = "Description for testUpdateWorkspace";
    // intents
    CreateIntent intent0 = new CreateIntent.Builder("Hello").build();
    CreateIntent intent1 = new CreateIntent.Builder("Goodbye").build();
    // entities
    CreateEntity entity0 = new CreateEntity.Builder("animal").build();
    CreateEntity entity1 = new CreateEntity.Builder("beverage").build();
    // counterexamples
    CreateCounterexample counterexample0 = new CreateCounterexample.Builder("What are you wearing?").build();
    CreateCounterexample counterexample1 = new CreateCounterexample.Builder("What are you eating?").build();
    CreateWorkspaceOptions createOptions = new CreateWorkspaceOptions.Builder().name(workspaceName).description(workspaceDescription).addIntent(intent0).addIntent(intent1).addEntity(entity0).addEntity(entity1).addCounterexample(counterexample0).addCounterexample(counterexample1).build();
    String workspaceId = null;
    try {
        Workspace createResponse = service.createWorkspace(createOptions).execute();
        assertNotNull(createResponse);
        assertNotNull(createResponse.getWorkspaceId());
        workspaceId = createResponse.getWorkspaceId();
        String counterExampleText = "What are you drinking";
        CreateCounterexample counterexample2 = new CreateCounterexample.Builder(counterExampleText).build();
        UpdateWorkspaceOptions updateOptions = new UpdateWorkspaceOptions.Builder(workspaceId).addCounterexample(counterexample2).append(false).build();
        Workspace updateResponse = service.updateWorkspace(updateOptions).execute();
        assertNotNull(updateResponse);
        GetCounterexampleOptions getOptions = new GetCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
        Counterexample eResponse = service.getCounterexample(getOptions).execute();
        assertNotNull(eResponse);
        assertNotNull(eResponse.getText());
        assertEquals(eResponse.getText(), counterExampleText);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        if (workspaceId != null) {
            DeleteWorkspaceOptions deleteOptions = new DeleteWorkspaceOptions.Builder(workspaceId).build();
            service.deleteWorkspace(deleteOptions).execute();
        }
    }
}
Also used : CreateEntity(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntity) DeleteWorkspaceOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteWorkspaceOptions) UpdateWorkspaceOptions(com.ibm.watson.developer_cloud.assistant.v1.model.UpdateWorkspaceOptions) CreateIntent(com.ibm.watson.developer_cloud.assistant.v1.model.CreateIntent) 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) CreateCounterexample(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample) CreateWorkspaceOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateWorkspaceOptions) GetCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetCounterexampleOptions) Workspace(com.ibm.watson.developer_cloud.assistant.v1.model.Workspace) Test(org.junit.Test)

Aggregations

NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)6 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)6 Test (org.junit.Test)6 GetCounterexampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.GetCounterexampleOptions)3 Counterexample (com.ibm.watson.developer_cloud.conversation.v1.model.Counterexample)3 GetCounterexampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.GetCounterexampleOptions)3 Counterexample (com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample)2 CreateCounterexample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample)2 CreateCounterexampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions)2 DeleteCounterexampleOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteCounterexampleOptions)2 CreateCounterexample (com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexample)2 CreateCounterexampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexampleOptions)2 DeleteCounterexampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteCounterexampleOptions)2 Date (java.util.Date)2 CreateEntity (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntity)1 CreateIntent (com.ibm.watson.developer_cloud.assistant.v1.model.CreateIntent)1 CreateWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateWorkspaceOptions)1 DeleteWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteWorkspaceOptions)1 UpdateWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateWorkspaceOptions)1 Workspace (com.ibm.watson.developer_cloud.assistant.v1.model.Workspace)1