Search in sources :

Example 36 with Entity

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

the class Conversation method getEntity.

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

Example 37 with Entity

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

the class Conversation method updateValue.

/**
 * Update entity value.
 *
 * Update the content of a value for an entity.
 *
 * @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.conversation.v1.model.Value) JsonObject(com.google.gson.JsonObject)

Example 38 with Entity

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

the class Conversation method updateEntity.

/**
 * Update entity.
 *
 * Update an existing entity with new or modified data.
 *
 * @param updateEntityOptions the {@link UpdateEntityOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Entity}
 */
public ServiceCall<Entity> updateEntity(UpdateEntityOptions updateEntityOptions) {
    Validator.notNull(updateEntityOptions, "updateEntityOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities" };
    String[] pathParameters = { updateEntityOptions.workspaceId(), updateEntityOptions.entity() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (updateEntityOptions.newFuzzyMatch() != null) {
        contentJson.addProperty("fuzzy_match", updateEntityOptions.newFuzzyMatch());
    }
    if (updateEntityOptions.newEntity() != null) {
        contentJson.addProperty("entity", updateEntityOptions.newEntity());
    }
    if (updateEntityOptions.newMetadata() != null) {
        contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(updateEntityOptions.newMetadata()));
    }
    if (updateEntityOptions.newValues() != null) {
        contentJson.add("values", GsonSingleton.getGson().toJsonTree(updateEntityOptions.newValues()));
    }
    if (updateEntityOptions.newDescription() != null) {
        contentJson.addProperty("description", updateEntityOptions.newDescription());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Entity.class));
}
Also used : Entity(com.ibm.watson.developer_cloud.conversation.v1.model.Entity) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject)

Example 39 with Entity

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

the class Conversation method getSynonym.

/**
 * Get entity value synonym.
 *
 * Get information about a synonym for an entity value.
 *
 * @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.conversation.v1.model.Synonym)

Example 40 with Entity

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

the class Assistant method createEntity.

/**
 * Create entity.
 *
 * Create a new entity. This operation is limited to 1000 requests per 30 minutes. For more information, see **Rate
 * limiting**.
 *
 * @param createEntityOptions the {@link CreateEntityOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Entity}
 */
public ServiceCall<Entity> createEntity(CreateEntityOptions createEntityOptions) {
    Validator.notNull(createEntityOptions, "createEntityOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities" };
    String[] pathParameters = { createEntityOptions.workspaceId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("entity", createEntityOptions.entity());
    if (createEntityOptions.description() != null) {
        contentJson.addProperty("description", createEntityOptions.description());
    }
    if (createEntityOptions.metadata() != null) {
        contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(createEntityOptions.metadata()));
    }
    if (createEntityOptions.values() != null) {
        contentJson.add("values", GsonSingleton.getGson().toJsonTree(createEntityOptions.values()));
    }
    if (createEntityOptions.fuzzyMatch() != null) {
        contentJson.addProperty("fuzzy_match", createEntityOptions.fuzzyMatch());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Entity.class));
}
Also used : Entity(com.ibm.watson.developer_cloud.assistant.v1.model.Entity) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject)

Aggregations

Test (org.junit.Test)28 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)22 CreateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions)19 CreateValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions)13 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)13 JsonObject (com.google.gson.JsonObject)9 Synonym (com.ibm.watson.developer_cloud.conversation.v1.model.Synonym)8 HashMap (java.util.HashMap)7 CreateSynonymOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateSynonymOptions)6 CreateValue (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue)6 DeleteEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteEntityOptions)6 DeleteSynonymOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteSynonymOptions)6 DeleteValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteValueOptions)6 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)5 Entity (com.ibm.watson.developer_cloud.assistant.v1.model.Entity)5 Entity (com.ibm.watson.developer_cloud.conversation.v1.model.Entity)5 Value (com.ibm.watson.developer_cloud.conversation.v1.model.Value)5 ValueExport (com.ibm.watson.developer_cloud.conversation.v1.model.ValueExport)5 EntityExport (com.ibm.watson.developer_cloud.conversation.v1.model.EntityExport)4 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)3