Search in sources :

Example 1 with GetSynonymOptions

use of com.ibm.watson.developer_cloud.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();
    } 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"));
    }
    Date start = new Date();
    CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
    service.createSynonym(createOptions).execute();
    try {
        GetSynonymOptions getOptions = new GetSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).includeAudit(true).build();
        Synonym response = service.getSynonym(getOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getSynonymText());
        assertEquals(response.getSynonymText(), synonym);
        assertNotNull(response.getCreated());
        assertNotNull(response.getUpdated());
        Date now = new Date();
        assertTrue(fuzzyBefore(response.getCreated(), now));
        assertTrue(fuzzyAfter(response.getCreated(), start));
        assertTrue(fuzzyBefore(response.getUpdated(), now));
        assertTrue(fuzzyAfter(response.getUpdated(), start));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
        service.deleteSynonym(deleteOptions).execute();
    }
}
Also used : DeleteSynonymOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteSynonymOptions) CreateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions) CreateValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions) GetSynonymOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetSynonymOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Date(java.util.Date) CreateSynonymOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateSynonymOptions) Synonym(com.ibm.watson.developer_cloud.conversation.v1.model.Synonym) Test(org.junit.Test)

Example 2 with GetSynonymOptions

use of com.ibm.watson.developer_cloud.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();
    } 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"));
    }
    Date start = new Date();
    CreateSynonymOptions createOptions = new CreateSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
    service.createSynonym(createOptions).execute();
    try {
        GetSynonymOptions getOptions = new GetSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).includeAudit(true).build();
        Synonym response = service.getSynonym(getOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getSynonymText());
        assertEquals(response.getSynonymText(), synonym);
        assertNotNull(response.getCreated());
        assertNotNull(response.getUpdated());
        Date now = new Date();
        assertTrue(fuzzyBefore(response.getCreated(), now));
        assertTrue(fuzzyAfter(response.getCreated(), start));
        assertTrue(fuzzyBefore(response.getUpdated(), now));
        assertTrue(fuzzyAfter(response.getUpdated(), start));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        DeleteSynonymOptions deleteOptions = new DeleteSynonymOptions.Builder(workspaceId, entity, entityValue, synonym).build();
        service.deleteSynonym(deleteOptions).execute();
    }
}
Also used : DeleteSynonymOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteSynonymOptions) CreateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions) CreateValueOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions) GetSynonymOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetSynonymOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Date(java.util.Date) CreateSynonymOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateSynonymOptions) Synonym(com.ibm.watson.developer_cloud.assistant.v1.model.Synonym) Test(org.junit.Test)

Example 3 with GetSynonymOptions

use of com.ibm.watson.developer_cloud.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);
    }
}
Also used : DeleteSynonymOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteSynonymOptions) CreateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions) CreateValueOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions) GetSynonymOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetSynonymOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) CreateSynonymOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateSynonymOptions) Synonym(com.ibm.watson.developer_cloud.assistant.v1.model.Synonym) Test(org.junit.Test)

Example 4 with GetSynonymOptions

use of com.ibm.watson.developer_cloud.assistant.v1.model.GetSynonymOptions 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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Synonym(com.ibm.watson.developer_cloud.assistant.v1.model.Synonym)

Example 5 with GetSynonymOptions

use of com.ibm.watson.developer_cloud.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);
    }
}
Also used : DeleteSynonymOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteSynonymOptions) CreateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions) CreateValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions) GetSynonymOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetSynonymOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) CreateSynonymOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateSynonymOptions) Synonym(com.ibm.watson.developer_cloud.conversation.v1.model.Synonym) Test(org.junit.Test)

Aggregations

NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)4 Test (org.junit.Test)4 Synonym (com.ibm.watson.developer_cloud.assistant.v1.model.Synonym)3 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)2 CreateSynonymOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateSynonymOptions)2 CreateValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions)2 DeleteSynonymOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteSynonymOptions)2 GetSynonymOptions (com.ibm.watson.developer_cloud.assistant.v1.model.GetSynonymOptions)2 CreateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions)2 CreateSynonymOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateSynonymOptions)2 CreateValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions)2 DeleteSynonymOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteSynonymOptions)2 GetSynonymOptions (com.ibm.watson.developer_cloud.conversation.v1.model.GetSynonymOptions)2 Synonym (com.ibm.watson.developer_cloud.conversation.v1.model.Synonym)2 Date (java.util.Date)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1