Search in sources :

Example 11 with Counterexample

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

the class Assistant method getCounterexample.

/**
 * Get counterexample.
 *
 * <p>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 result of type {@link Counterexample}
 */
public ServiceCall<Counterexample> getCounterexample(GetCounterexampleOptions getCounterexampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getCounterexampleOptions, "getCounterexampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", getCounterexampleOptions.workspaceId());
    pathParamsMap.put("text", getCounterexampleOptions.text());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/counterexamples/{text}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "getCounterexample");
    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));
    if (getCounterexampleOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getCounterexampleOptions.includeAudit()));
    }
    ResponseConverter<Counterexample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Counterexample>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Counterexample(com.ibm.watson.assistant.v1.model.Counterexample)

Example 12 with Counterexample

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

the class Assistant method updateCounterexample.

/**
 * Update counterexample.
 *
 * <p>Update the text of a counterexample. Counterexamples are examples that have been marked as
 * irrelevant input.
 *
 * @param updateCounterexampleOptions the {@link UpdateCounterexampleOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link Counterexample}
 */
public ServiceCall<Counterexample> updateCounterexample(UpdateCounterexampleOptions updateCounterexampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateCounterexampleOptions, "updateCounterexampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateCounterexampleOptions.workspaceId());
    pathParamsMap.put("text", updateCounterexampleOptions.text());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/counterexamples/{text}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateCounterexample");
    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));
    if (updateCounterexampleOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateCounterexampleOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateCounterexampleOptions.newText() != null) {
        contentJson.addProperty("text", updateCounterexampleOptions.newText());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Counterexample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Counterexample>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Counterexample(com.ibm.watson.assistant.v1.model.Counterexample)

Example 13 with Counterexample

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

the class Assistant method createCounterexample.

/**
 * Create counterexample.
 *
 * <p>Add a new counterexample to a workspace. Counterexamples are examples that have been marked
 * as irrelevant input.
 *
 * <p>If you want to add multiple counterexamples with a single API call, consider using the
 * **[Update workspace](#update-workspace)** method instead.
 *
 * @param createCounterexampleOptions the {@link CreateCounterexampleOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link Counterexample}
 */
public ServiceCall<Counterexample> createCounterexample(CreateCounterexampleOptions createCounterexampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createCounterexampleOptions, "createCounterexampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", createCounterexampleOptions.workspaceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/counterexamples", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "createCounterexample");
    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));
    if (createCounterexampleOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(createCounterexampleOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("text", createCounterexampleOptions.text());
    builder.bodyJson(contentJson);
    ResponseConverter<Counterexample> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Counterexample>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Counterexample(com.ibm.watson.assistant.v1.model.Counterexample)

Example 14 with Counterexample

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

the class AssistantServiceIT method testUpdateCounterexample.

/**
 * Test updateCounterexample.
 */
@Test
public void testUpdateCounterexample() {
    // gotta be unique
    String counterExampleText = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    // gotta be unique
    String counterExampleText2 = "Make me a " + UUID.randomUUID().toString() + " sandwich";
    CreateCounterexampleOptions createOptions = new CreateCounterexampleOptions.Builder(workspaceId, counterExampleText).build();
    service.createCounterexample(createOptions).execute();
    try {
        UpdateCounterexampleOptions updateOptions = new UpdateCounterexampleOptions.Builder(workspaceId, counterExampleText).newText(counterExampleText2).build();
        Counterexample response = service.updateCounterexample(updateOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getText());
        assertEquals(response.getText(), counterExampleText2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteCounterexampleOptions deleteOptions = new DeleteCounterexampleOptions.Builder(workspaceId, counterExampleText2).build();
        service.deleteCounterexample(deleteOptions).execute();
    }
}
Also used : CreateCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexampleOptions) UpdateCounterexampleOptions(com.ibm.watson.developer_cloud.assistant.v1.model.UpdateCounterexampleOptions) 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 15 with Counterexample

use of com.ibm.watson.assistant.v1.model.Counterexample 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)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