Search in sources :

Example 6 with Synonym

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

the class Conversation method createSynonym.

/**
 * Add entity value synonym.
 *
 * Add a new synonym to an entity value.
 *
 * @param createSynonymOptions the {@link CreateSynonymOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Synonym}
 */
public ServiceCall<Synonym> createSynonym(CreateSynonymOptions createSynonymOptions) {
    Validator.notNull(createSynonymOptions, "createSynonymOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities", "values", "synonyms" };
    String[] pathParameters = { createSynonymOptions.workspaceId(), createSynonymOptions.entity(), createSynonymOptions.value() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("synonym", createSynonymOptions.synonym());
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Synonym.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Synonym(com.ibm.watson.developer_cloud.conversation.v1.model.Synonym)

Example 7 with Synonym

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

the class Conversation method updateSynonym.

/**
 * Update entity value synonym.
 *
 * Update the information about a synonym for an entity value.
 *
 * @param updateSynonymOptions the {@link UpdateSynonymOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Synonym}
 */
public ServiceCall<Synonym> updateSynonym(UpdateSynonymOptions updateSynonymOptions) {
    Validator.notNull(updateSynonymOptions, "updateSynonymOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities", "values", "synonyms" };
    String[] pathParameters = { updateSynonymOptions.workspaceId(), updateSynonymOptions.entity(), updateSynonymOptions.value(), updateSynonymOptions.synonym() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (updateSynonymOptions.newSynonym() != null) {
        contentJson.addProperty("synonym", updateSynonymOptions.newSynonym());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Synonym.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Synonym(com.ibm.watson.developer_cloud.conversation.v1.model.Synonym)

Example 8 with Synonym

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

the class Assistant method createSynonym.

/**
 * Add entity value synonym.
 *
 * Add a new synonym to an entity value. This operation is limited to 1000 requests per 30 minutes. For more
 * information, see **Rate limiting**.
 *
 * @param createSynonymOptions the {@link CreateSynonymOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Synonym}
 */
public ServiceCall<Synonym> createSynonym(CreateSynonymOptions createSynonymOptions) {
    Validator.notNull(createSynonymOptions, "createSynonymOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities", "values", "synonyms" };
    String[] pathParameters = { createSynonymOptions.workspaceId(), createSynonymOptions.entity(), createSynonymOptions.value() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("synonym", createSynonymOptions.synonym());
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Synonym.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Synonym(com.ibm.watson.developer_cloud.assistant.v1.model.Synonym)

Example 9 with Synonym

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

the class Assistant method getSynonym.

/**
 * Get entity value synonym.
 *
 * Get information about a synonym of an entity value. This operation is limited to 6000 requests per 5 minutes. For
 * more information, see **Rate limiting**.
 *
 * @param getSynonymOptions the {@link GetSynonymOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Synonym}
 */
public ServiceCall<Synonym> getSynonym(GetSynonymOptions getSynonymOptions) {
    Validator.notNull(getSynonymOptions, "getSynonymOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities", "values", "synonyms" };
    String[] pathParameters = { getSynonymOptions.workspaceId(), getSynonymOptions.entity(), getSynonymOptions.value(), getSynonymOptions.synonym() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (getSynonymOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getSynonymOptions.includeAudit()));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Synonym.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Synonym(com.ibm.watson.developer_cloud.assistant.v1.model.Synonym)

Example 10 with Synonym

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

the class AssistantTest method testGetValueWOptions.

// Test the getValue operation with a valid options model parameter
@Test
public void testGetValueWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"value\": \"value\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"type\": \"synonyms\", \"synonyms\": [\"synonym\"], \"patterns\": [\"pattern\"], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String getValuePath = "/v1/workspaces/testString/entities/testString/values/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetValueOptions model
    GetValueOptions getValueOptionsModel = new GetValueOptions.Builder().workspaceId("testString").entity("testString").value("testString").export(false).includeAudit(false).build();
    // Invoke getValue() with a valid options model and verify the result
    Response<Value> response = assistantService.getValue(getValueOptionsModel).execute();
    assertNotNull(response);
    Value 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, getValuePath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("export")), Boolean.valueOf(false));
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetValueOptions(com.ibm.watson.assistant.v1.model.GetValueOptions) DialogNodeOutputOptionsElementValue(com.ibm.watson.assistant.v1.model.DialogNodeOutputOptionsElementValue) CreateValue(com.ibm.watson.assistant.v1.model.CreateValue) Value(com.ibm.watson.assistant.v1.model.Value) Test(org.testng.annotations.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)17 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)17 Test (org.testng.annotations.Test)17 Test (org.junit.Test)16 Synonym (com.ibm.watson.assistant.v1.model.Synonym)11 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)10 Synonym (com.ibm.watson.developer_cloud.assistant.v1.model.Synonym)8 Synonym (com.ibm.watson.developer_cloud.conversation.v1.model.Synonym)8 CreateEntityOptions (com.ibm.watson.assistant.v1.model.CreateEntityOptions)7 CreateSynonymOptions (com.ibm.watson.assistant.v1.model.CreateSynonymOptions)7 CreateValue (com.ibm.watson.assistant.v1.model.CreateValue)7 CreateValueOptions (com.ibm.watson.assistant.v1.model.CreateValueOptions)7 DeleteSynonymOptions (com.ibm.watson.assistant.v1.model.DeleteSynonymOptions)7 HashMap (java.util.HashMap)7 JsonObject (com.google.gson.JsonObject)6 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)6 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)6 CreateEntity (com.ibm.watson.assistant.v1.model.CreateEntity)5 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)5 CreateSynonymOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateSynonymOptions)5