use of com.ibm.watson.developer_cloud.conversation.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));
}
use of com.ibm.watson.developer_cloud.conversation.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));
}
use of com.ibm.watson.developer_cloud.conversation.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));
}
use of com.ibm.watson.developer_cloud.conversation.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));
}
use of com.ibm.watson.developer_cloud.conversation.v1.model.Synonym in project java-sdk by watson-developer-cloud.
the class SynonymsIT method testCreateSynonym.
/**
* Test createSynonym.
*/
@Test
public void testCreateSynonym() {
String entity = "beverage";
String entityValue = "orange juice";
String synonym = "OJ";
try {
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
service.createEntity(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).build();
service.createValue(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).synonym(synonym).build();
Synonym response = service.createSynonym(createOptions).execute();
try {
assertNotNull(response);
assertNotNull(response.getSynonymText());
assertEquals(response.getSynonymText(), synonym);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
service.deleteSynonym(deleteOptions).execute();
}
}
Aggregations