Search in sources :

Example 1 with Conversions

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

the class DiscoveryServiceIT method createConfigurationIsSuccessful.

@Test
public void createConfigurationIsSuccessful() {
    Date start = new Date();
    String uniqueConfigName = uniqueName + "-config";
    String description = "Description of " + uniqueConfigName;
    Conversions conversions = new Conversions();
    HtmlSettings htmlSettings = new HtmlSettings();
    htmlSettings.setExcludeTagsCompletely(Arrays.asList("table", "h6", "header"));
    conversions.setHtml(htmlSettings);
    NormalizationOperation operation = new NormalizationOperation();
    operation.setOperation("foo");
    operation.setSourceField("bar");
    operation.setDestinationField("baz");
    List<NormalizationOperation> normalizations = Arrays.asList(operation);
    Enrichment enrichment = new Enrichment();
    enrichment.setSourceField("foo");
    enrichment.setDestinationField("bar");
    enrichment.setEnrichmentName("baz");
    enrichment.setDescription("Erich foo to bar with baz");
    enrichment.setIgnoreDownstreamErrors(true);
    enrichment.setOverwrite(false);
    NluEnrichmentSentiment sentiment = new NluEnrichmentSentiment.Builder().document(true).build();
    NluEnrichmentEmotion emotion = new NluEnrichmentEmotion.Builder().document(true).build();
    NluEnrichmentEntities entities = new NluEnrichmentEntities.Builder().emotion(true).sentiment(true).model("WhatComesAfterQux").build();
    NluEnrichmentKeywords keywords = new NluEnrichmentKeywords.Builder().emotion(true).sentiment(true).build();
    NluEnrichmentSemanticRoles semanticRoles = new NluEnrichmentSemanticRoles.Builder().entities(true).build();
    NluEnrichmentFeatures features = new NluEnrichmentFeatures.Builder().sentiment(sentiment).emotion(emotion).entities(entities).keywords(keywords).semanticRoles(semanticRoles).build();
    EnrichmentOptions options = new EnrichmentOptions.Builder().features(features).build();
    enrichment.setOptions(options);
    List<Enrichment> enrichments = Arrays.asList(enrichment);
    CreateConfigurationOptions createOptions = new CreateConfigurationOptions.Builder().environmentId(environmentId).name(uniqueConfigName).description(description).conversions(conversions).normalizations(normalizations).enrichments(enrichments).build();
    Configuration createResponse = createConfiguration(createOptions);
    assertEquals(uniqueConfigName, createResponse.getName());
    assertEquals(description, createResponse.getDescription());
    assertEquals(conversions, createResponse.getConversions());
    assertEquals(normalizations, createResponse.getNormalizations());
    assertEquals(enrichments, createResponse.getEnrichments());
    Date now = new Date();
    assertTrue(fuzzyBefore(createResponse.getCreated(), now));
    assertTrue(fuzzyAfter(createResponse.getCreated(), start));
    assertTrue(fuzzyBefore(createResponse.getUpdated(), now));
    assertTrue(fuzzyAfter(createResponse.getUpdated(), start));
}
Also used : Enrichment(com.ibm.watson.developer_cloud.discovery.v1.model.Enrichment) NluEnrichmentEmotion(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentEmotion) CreateConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions) NluEnrichmentEntities(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentEntities) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) NormalizationOperation(com.ibm.watson.developer_cloud.discovery.v1.model.NormalizationOperation) NluEnrichmentSentiment(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentSentiment) NluEnrichmentSemanticRoles(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentSemanticRoles) Date(java.util.Date) NluEnrichmentFeatures(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentFeatures) Conversions(com.ibm.watson.developer_cloud.discovery.v1.model.Conversions) HtmlSettings(com.ibm.watson.developer_cloud.discovery.v1.model.HtmlSettings) EnrichmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.EnrichmentOptions) NluEnrichmentKeywords(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentKeywords) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with Conversions

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

the class DiscoveryServiceIT method updateConfigurationIsSuccessful.

@Test
public void updateConfigurationIsSuccessful() {
    Configuration testConfig = createTestConfig();
    Date start = new Date();
    String updatedName = testConfig.getName() + UUID.randomUUID().toString();
    String updatedDescription = "Description of " + updatedName;
    Conversions updatedConversions = new Conversions();
    HtmlSettings newHtmlSettings = new HtmlSettings();
    newHtmlSettings.setExcludeTagsCompletely(Arrays.asList("table", "h6", "header"));
    updatedConversions.setHtml(newHtmlSettings);
    NormalizationOperation operation = new NormalizationOperation();
    operation.setOperation("foo");
    operation.setSourceField("bar");
    operation.setDestinationField("baz");
    List<NormalizationOperation> updatedNormalizations = Arrays.asList(operation);
    Enrichment enrichment = new Enrichment();
    enrichment.setSourceField("foo");
    enrichment.setDestinationField("bar");
    enrichment.setEnrichmentName("baz");
    enrichment.setDescription("Erich foo to bar with baz");
    enrichment.setIgnoreDownstreamErrors(true);
    enrichment.setOverwrite(false);
    NluEnrichmentSentiment sentiment = new NluEnrichmentSentiment.Builder().document(true).build();
    NluEnrichmentEmotion emotion = new NluEnrichmentEmotion.Builder().document(true).build();
    NluEnrichmentEntities entities = new NluEnrichmentEntities.Builder().emotion(true).sentiment(true).model("WhatComesAfterQux").build();
    NluEnrichmentKeywords keywords = new NluEnrichmentKeywords.Builder().emotion(true).sentiment(true).build();
    NluEnrichmentSemanticRoles semanticRoles = new NluEnrichmentSemanticRoles.Builder().entities(true).build();
    NluEnrichmentFeatures features = new NluEnrichmentFeatures.Builder().sentiment(sentiment).emotion(emotion).entities(entities).keywords(keywords).semanticRoles(semanticRoles).build();
    EnrichmentOptions options = new EnrichmentOptions.Builder().features(features).build();
    enrichment.setOptions(options);
    List<Enrichment> updatedEnrichments = Arrays.asList(enrichment);
    UpdateConfigurationOptions.Builder updateBuilder = new UpdateConfigurationOptions.Builder(environmentId, testConfig.getConfigurationId());
    updateBuilder.name(updatedName);
    updateBuilder.description(updatedDescription);
    updateBuilder.conversions(updatedConversions);
    updateBuilder.normalizations(updatedNormalizations);
    updateBuilder.enrichments(updatedEnrichments);
    Configuration updatedConfiguration = discovery.updateConfiguration(updateBuilder.build()).execute();
    assertEquals(updatedName, updatedConfiguration.getName());
    assertEquals(updatedDescription, updatedConfiguration.getDescription());
    assertEquals(updatedConversions, updatedConfiguration.getConversions());
    assertEquals(updatedNormalizations, updatedConfiguration.getNormalizations());
    assertEquals(updatedEnrichments, updatedConfiguration.getEnrichments());
    Date now = new Date();
    assertTrue(fuzzyBefore(updatedConfiguration.getCreated(), start));
    assertTrue(fuzzyBefore(updatedConfiguration.getUpdated(), now));
    assertTrue(fuzzyAfter(updatedConfiguration.getUpdated(), start));
}
Also used : Enrichment(com.ibm.watson.developer_cloud.discovery.v1.model.Enrichment) NluEnrichmentEmotion(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentEmotion) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) NluEnrichmentEntities(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentEntities) NormalizationOperation(com.ibm.watson.developer_cloud.discovery.v1.model.NormalizationOperation) NluEnrichmentSentiment(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentSentiment) NluEnrichmentSemanticRoles(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentSemanticRoles) Date(java.util.Date) NluEnrichmentFeatures(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentFeatures) Conversions(com.ibm.watson.developer_cloud.discovery.v1.model.Conversions) HtmlSettings(com.ibm.watson.developer_cloud.discovery.v1.model.HtmlSettings) EnrichmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.EnrichmentOptions) UpdateConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateConfigurationOptions) NluEnrichmentKeywords(com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentKeywords) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 3 with Conversions

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

the class Discovery method createConfiguration.

/**
 * Add configuration.
 *
 * Creates a new configuration. If the input configuration contains the `configuration_id`, `created`, or `updated`
 * properties, then they are ignored and overridden by the system, and an error is not returned so that the overridden
 * fields do not need to be removed when copying a configuration. The configuration can contain unrecognized JSON
 * fields. Any such fields are ignored and do not generate an error. This makes it easier to use newer configuration
 * files with older versions of the API and the service. It also makes it possible for the tooling to add additional
 * metadata and information to the configuration.
 *
 * @param createConfigurationOptions the {@link CreateConfigurationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Configuration}
 */
public ServiceCall<Configuration> createConfiguration(CreateConfigurationOptions createConfigurationOptions) {
    Validator.notNull(createConfigurationOptions, "createConfigurationOptions cannot be null");
    String[] pathSegments = { "v1/environments", "configurations" };
    String[] pathParameters = { createConfigurationOptions.environmentId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (createConfigurationOptions.name() != null) {
        contentJson.addProperty("name", createConfigurationOptions.name());
    }
    if (createConfigurationOptions.description() != null) {
        contentJson.addProperty("description", createConfigurationOptions.description());
    }
    if (createConfigurationOptions.conversions() != null) {
        contentJson.add("conversions", GsonSingleton.getGson().toJsonTree(createConfigurationOptions.conversions()));
    }
    if (createConfigurationOptions.enrichments() != null) {
        contentJson.add("enrichments", GsonSingleton.getGson().toJsonTree(createConfigurationOptions.enrichments()));
    }
    if (createConfigurationOptions.normalizations() != null) {
        contentJson.add("normalizations", GsonSingleton.getGson().toJsonTree(createConfigurationOptions.normalizations()));
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Configuration.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) JsonObject(com.google.gson.JsonObject)

Example 4 with Conversions

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

the class Discovery method updateConfiguration.

/**
 * Update a configuration.
 *
 * Replaces an existing configuration. * Completely replaces the original configuration. * The `configuration_id`,
 * `updated`, and `created` fields are accepted in the request, but they are ignored, and an error is not generated.
 * It is also acceptable for users to submit an updated configuration with none of the three properties. * Documents
 * are processed with a snapshot of the configuration as it was at the time the document was submitted to be ingested.
 * This means that already submitted documents will not see any updates made to the configuration.
 *
 * @param updateConfigurationOptions the {@link UpdateConfigurationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Configuration}
 */
public ServiceCall<Configuration> updateConfiguration(UpdateConfigurationOptions updateConfigurationOptions) {
    Validator.notNull(updateConfigurationOptions, "updateConfigurationOptions cannot be null");
    String[] pathSegments = { "v1/environments", "configurations" };
    String[] pathParameters = { updateConfigurationOptions.environmentId(), updateConfigurationOptions.configurationId() };
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (updateConfigurationOptions.name() != null) {
        contentJson.addProperty("name", updateConfigurationOptions.name());
    }
    if (updateConfigurationOptions.description() != null) {
        contentJson.addProperty("description", updateConfigurationOptions.description());
    }
    if (updateConfigurationOptions.conversions() != null) {
        contentJson.add("conversions", GsonSingleton.getGson().toJsonTree(updateConfigurationOptions.conversions()));
    }
    if (updateConfigurationOptions.enrichments() != null) {
        contentJson.add("enrichments", GsonSingleton.getGson().toJsonTree(updateConfigurationOptions.enrichments()));
    }
    if (updateConfigurationOptions.normalizations() != null) {
        contentJson.add("normalizations", GsonSingleton.getGson().toJsonTree(updateConfigurationOptions.normalizations()));
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Configuration.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) JsonObject(com.google.gson.JsonObject)

Aggregations

Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)4 JsonObject (com.google.gson.JsonObject)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 Conversions (com.ibm.watson.developer_cloud.discovery.v1.model.Conversions)2 Enrichment (com.ibm.watson.developer_cloud.discovery.v1.model.Enrichment)2 EnrichmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.EnrichmentOptions)2 HtmlSettings (com.ibm.watson.developer_cloud.discovery.v1.model.HtmlSettings)2 NluEnrichmentEmotion (com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentEmotion)2 NluEnrichmentEntities (com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentEntities)2 NluEnrichmentFeatures (com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentFeatures)2 NluEnrichmentKeywords (com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentKeywords)2 NluEnrichmentSemanticRoles (com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentSemanticRoles)2 NluEnrichmentSentiment (com.ibm.watson.developer_cloud.discovery.v1.model.NluEnrichmentSentiment)2 NormalizationOperation (com.ibm.watson.developer_cloud.discovery.v1.model.NormalizationOperation)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 Date (java.util.Date)2 Test (org.junit.Test)2 CreateConfigurationOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions)1 UpdateConfigurationOptions (com.ibm.watson.developer_cloud.discovery.v1.model.UpdateConfigurationOptions)1