Search in sources :

Example 1 with CreateConfigurationOptions

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

the class DiscoveryServiceIT method issueNumber659.

/* Issue 659: creating a collection does not use the configuration id */
@Test
public void issueNumber659() {
    String uniqueConfigName = UUID.randomUUID().toString() + "-config";
    Configuration testConfiguration = getTestConfiguration(DISCOVERY_TEST_CONFIG_FILE);
    CreateConfigurationOptions configOptions = new CreateConfigurationOptions.Builder(environmentId).configuration(testConfiguration).name(uniqueConfigName).build();
    Configuration configuration = discovery.createConfiguration(configOptions).execute();
    configurationIds.add(configuration.getConfigurationId());
    String uniqueCollectionName = UUID.randomUUID().toString() + "-collection";
    CreateCollectionOptions collectionOptions = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).configurationId(configuration.getConfigurationId()).build();
    Collection collection = discovery.createCollection(collectionOptions).execute();
    collectionIds.add(collection.getCollectionId());
    assertEquals(collection.getConfigurationId(), configuration.getConfigurationId());
}
Also used : CreateConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) CreateCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with CreateConfigurationOptions

use of com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions 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 3 with CreateConfigurationOptions

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

the class DiscoveryServiceIT method createConfiguration.

private Configuration createConfiguration(CreateConfigurationOptions createOptions) {
    Configuration createResponse = discovery.createConfiguration(createOptions).execute();
    configurationIds.add(createResponse.getConfigurationId());
    return createResponse;
}
Also used : Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)

Example 4 with CreateConfigurationOptions

use of com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions 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)

Aggregations

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