Search in sources :

Example 16 with Value

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

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

the class Conversation method getValue.

/**
 * Get entity value.
 *
 * Get information about an entity value.
 *
 * @param getValueOptions the {@link GetValueOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link ValueExport}
 */
public ServiceCall<ValueExport> getValue(GetValueOptions getValueOptions) {
    Validator.notNull(getValueOptions, "getValueOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities", "values" };
    String[] pathParameters = { getValueOptions.workspaceId(), getValueOptions.entity(), getValueOptions.value() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (getValueOptions.export() != null) {
        builder.query("export", String.valueOf(getValueOptions.export()));
    }
    if (getValueOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getValueOptions.includeAudit()));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ValueExport.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) ValueExport(com.ibm.watson.developer_cloud.conversation.v1.model.ValueExport)

Example 18 with Value

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

the class Assistant method updateValue.

/**
 * Update entity value.
 *
 * Update an existing entity value with new or modified data. You must provide component objects defining the content
 * of the updated entity value. This operation is limited to 1000 requests per 30 minutes. For more information, see
 * **Rate limiting**.
 *
 * @param updateValueOptions the {@link UpdateValueOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Value}
 */
public ServiceCall<Value> updateValue(UpdateValueOptions updateValueOptions) {
    Validator.notNull(updateValueOptions, "updateValueOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities", "values" };
    String[] pathParameters = { updateValueOptions.workspaceId(), updateValueOptions.entity(), updateValueOptions.value() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (updateValueOptions.newSynonyms() != null) {
        contentJson.add("synonyms", GsonSingleton.getGson().toJsonTree(updateValueOptions.newSynonyms()));
    }
    if (updateValueOptions.valueType() != null) {
        contentJson.addProperty("type", updateValueOptions.valueType());
    }
    if (updateValueOptions.newMetadata() != null) {
        contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(updateValueOptions.newMetadata()));
    }
    if (updateValueOptions.newPatterns() != null) {
        contentJson.add("patterns", GsonSingleton.getGson().toJsonTree(updateValueOptions.newPatterns()));
    }
    if (updateValueOptions.newValue() != null) {
        contentJson.addProperty("value", updateValueOptions.newValue());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Value.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Value(com.ibm.watson.developer_cloud.assistant.v1.model.Value) JsonObject(com.google.gson.JsonObject)

Example 19 with Value

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

the class ConversationTest method testCreateValueOptionsBuilder.

/**
 * Test CreateValueOptions builder.
 */
@Test
public void testCreateValueOptionsBuilder() {
    String entity = "anEntity";
    String value = "aValue";
    String valueSynonym0 = "valueSynonym0";
    String valueSynonym1 = "valueSynonym1";
    String valuePattern0 = "valuePattern0";
    String valuePattern1 = "valuePattern1";
    String valueType = "patterns";
    CreateValueOptions createOptions = new CreateValueOptions.Builder().workspaceId(WORKSPACE_ID).entity(entity).value(value).addSynonym(valueSynonym0).addSynonym(valueSynonym1).addPattern(valuePattern0).addPattern(valuePattern1).valueType(valueType).build();
    assertEquals(createOptions.workspaceId(), WORKSPACE_ID);
    assertEquals(createOptions.entity(), entity);
    assertEquals(createOptions.value(), value);
    assertEquals(createOptions.synonyms().size(), 2);
    assertEquals(createOptions.synonyms().get(0), valueSynonym0);
    assertEquals(createOptions.synonyms().get(1), valueSynonym1);
    assertEquals(createOptions.patterns().size(), 2);
    assertEquals(createOptions.patterns().get(0), valuePattern0);
    assertEquals(createOptions.patterns().get(1), valuePattern1);
    assertEquals(createOptions.valueType(), valueType);
    CreateValueOptions.Builder builder = createOptions.newBuilder();
    String valueSynonym2 = "valueSynonym2";
    String valuePattern2 = "valuePattern2";
    builder.synonyms(Arrays.asList(valueSynonym2));
    builder.patterns(Arrays.asList(valuePattern2));
    CreateValueOptions options2 = builder.build();
    assertEquals(options2.workspaceId(), WORKSPACE_ID);
    assertEquals(options2.entity(), entity);
    assertEquals(options2.value(), value);
    assertEquals(options2.synonyms().size(), 1);
    assertEquals(options2.synonyms().get(0), valueSynonym2);
    assertEquals(options2.patterns().size(), 1);
    assertEquals(options2.patterns().get(0), valuePattern2);
}
Also used : CreateValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 20 with Value

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

the class ConversationTest method testUpdateValueOptionsBuilder.

/**
 * Test UpdateValueOptions builder.
 */
@Test
public void testUpdateValueOptionsBuilder() {
    String entity = "anEntity";
    String value = "aValue";
    String newValue = "renamedValue";
    String valueSynonym0 = "valueSynonym0";
    String valueSynonym1 = "valueSynonym1";
    UpdateValueOptions updateOptions = new UpdateValueOptions.Builder().workspaceId(WORKSPACE_ID).entity(entity).value(value).newValue(newValue).addSynonym(valueSynonym0).addSynonym(valueSynonym1).build();
    assertEquals(updateOptions.workspaceId(), WORKSPACE_ID);
    assertEquals(updateOptions.entity(), entity);
    assertEquals(updateOptions.newValue(), newValue);
    assertEquals(updateOptions.newSynonyms().size(), 2);
    assertEquals(updateOptions.newSynonyms().get(0), valueSynonym0);
    assertEquals(updateOptions.newSynonyms().get(1), valueSynonym1);
    UpdateValueOptions.Builder builder = updateOptions.newBuilder();
    String valueSynonym2 = "valueSynonym2";
    builder.newSynonyms(Arrays.asList(valueSynonym2));
    UpdateValueOptions options2 = builder.build();
    assertEquals(options2.workspaceId(), WORKSPACE_ID);
    assertEquals(options2.entity(), entity);
    assertEquals(options2.newValue(), newValue);
    assertEquals(options2.newSynonyms().size(), 1);
    assertEquals(options2.newSynonyms().get(0), valueSynonym2);
}
Also used : UpdateValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.UpdateValueOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)17 CreateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions)14 CreateValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions)10 JsonObject (com.google.gson.JsonObject)9 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)9 HashMap (java.util.HashMap)9 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)7 Synonym (com.ibm.watson.developer_cloud.conversation.v1.model.Synonym)7 CreateValue (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue)6 Value (com.ibm.watson.developer_cloud.assistant.v1.model.Value)5 DeleteValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteValueOptions)5 Value (com.ibm.watson.developer_cloud.conversation.v1.model.Value)5 CreateSynonymOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateSynonymOptions)4 DeleteEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteEntityOptions)4 DeleteSynonymOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteSynonymOptions)4 ValueExport (com.ibm.watson.developer_cloud.conversation.v1.model.ValueExport)4 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)3 CreateValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions)3 DeleteValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteValueOptions)3