use of com.ibm.watson.assistant.v1.model.GetSynonymOptions in project java-sdk by watson-developer-cloud.
the class SynonymsIT method testDeleteSynonym.
/**
* Test deleteSynonym.
*/
@Test
public void testDeleteSynonym() {
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, entity, entityValue, synonym).build();
Synonym response = service.createSynonym(createOptions).execute();
try {
assertNotNull(response);
assertNotNull(response.getSynonymText());
assertEquals(response.getSynonymText(), synonym);
} catch (Exception ex) {
DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
service.deleteSynonym(deleteOptions).execute();
fail(ex.getMessage());
}
DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue).synonym(synonym).build();
service.deleteSynonym(deleteOptions).execute();
try {
GetSynonymOptions getOptions = new GetSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
service.getSynonym(getOptions).execute();
fail("deleteSynonym failed");
} catch (Exception ex) {
// Expected result
assertTrue(ex instanceof NotFoundException);
}
}
use of com.ibm.watson.assistant.v1.model.GetSynonymOptions in project java-sdk by watson-developer-cloud.
the class SynonymsIT method testGetSynonym.
/**
* Test getSynonym.
*/
@Test
public void testGetSynonym() {
String entity = "beverage";
String entityValue = "orange juice";
String synonym = "OJ";
try {
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
service.createEntity(createOptions).execute().getResult();
} 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().getResult();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
Date start = new Date();
CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
service.createSynonym(createOptions).execute().getResult();
try {
GetSynonymOptions getOptions = new GetSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).includeAudit(true).build();
Synonym response = service.getSynonym(getOptions).execute().getResult();
assertNotNull(response);
assertNotNull(response.synonym());
assertEquals(response.synonym(), synonym);
assertNotNull(response.created());
assertNotNull(response.updated());
Date now = new Date();
assertTrue(fuzzyBefore(response.created(), now));
assertTrue(fuzzyAfter(response.created(), start));
assertTrue(fuzzyBefore(response.updated(), now));
assertTrue(fuzzyAfter(response.updated(), start));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
service.deleteSynonym(deleteOptions).execute().getResult();
}
}
use of com.ibm.watson.assistant.v1.model.GetSynonymOptions in project java-sdk by watson-developer-cloud.
the class Assistant method getSynonym.
/**
* Get entity value synonym.
*
* <p>Get information about a synonym of an entity value.
*
* @param getSynonymOptions the {@link GetSynonymOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Synonym}
*/
public ServiceCall<Synonym> getSynonym(GetSynonymOptions getSynonymOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getSynonymOptions, "getSynonymOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("workspace_id", getSynonymOptions.workspaceId());
pathParamsMap.put("entity", getSynonymOptions.entity());
pathParamsMap.put("value", getSynonymOptions.value());
pathParamsMap.put("synonym", getSynonymOptions.synonym());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/values/{value}/synonyms/{synonym}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "getSynonym");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
if (getSynonymOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(getSynonymOptions.includeAudit()));
}
ResponseConverter<Synonym> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Synonym>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations