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());
}
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));
}
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;
}
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));
}
Aggregations