use of com.ibm.watson.developer_cloud.assistant.v1.model.UpdateSynonymOptions in project java-sdk by watson-developer-cloud.
the class SynonymsIT method testUpdateSynonym.
/**
* Test updateSynonym.
*/
@Test
public void testUpdateSynonym() {
String entity = "beverage";
String entityValue = "coffee";
String synonym1 = "joe";
String synonym2 = "mud";
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"));
}
try {
CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder(workspaceId, entity, entityValue, synonym1).build();
service.createSynonym(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
UpdateSynonymOptions updateOptions = new UpdateSynonymOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).synonym(synonym1).newSynonym(synonym2).build();
Synonym response = service.updateSynonym(updateOptions).execute();
try {
assertNotNull(response);
assertNotNull(response.getSynonymText());
assertEquals(response.getSynonymText(), synonym2);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym2).build();
service.deleteSynonym(deleteOptions).execute();
}
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.UpdateSynonymOptions in project java-sdk by watson-developer-cloud.
the class SynonymsIT method testUpdateSynonym.
/**
* Test updateSynonym.
*/
@Test
public void testUpdateSynonym() {
String entity = "beverage";
String entityValue = "coffee";
String synonym1 = "joe";
String synonym2 = "mud";
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"));
}
try {
CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder(workspaceId, entity, entityValue, synonym1).build();
service.createSynonym(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
UpdateSynonymOptions updateOptions = new UpdateSynonymOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).synonym(synonym1).newSynonym(synonym2).build();
Synonym response = service.updateSynonym(updateOptions).execute();
try {
assertNotNull(response);
assertNotNull(response.getSynonymText());
assertEquals(response.getSynonymText(), synonym2);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym2).build();
service.deleteSynonym(deleteOptions).execute();
}
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.UpdateSynonymOptions in project java-sdk by watson-developer-cloud.
the class Assistant method updateSynonym.
/**
* Update entity value synonym.
*
* Update an existing entity value synonym with new text. This operation is limited to 1000 requests per 30 minutes.
* For more information, see **Rate limiting**.
*
* @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));
}
Aggregations