Search in sources :

Example 1 with Configuration

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

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

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

the class DiscoveryServiceIT method createTestCollection.

private Collection createTestCollection() {
    Configuration createConfigResponse = createTestConfig();
    String uniqueCollectionName = uniqueName + "-collection";
    CreateCollectionOptions.Builder createCollectionBuilder = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).configurationId(createConfigResponse.getConfigurationId());
    Collection createResponse = createCollection(createCollectionBuilder.build());
    return createResponse;
}
Also used : 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)

Example 4 with Configuration

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

the class DiscoveryServiceIT method getConfigurationIsSuccessful.

@Test
public void getConfigurationIsSuccessful() {
    Configuration createResponse = createTestConfig();
    GetConfigurationOptions getOptions = new GetConfigurationOptions.Builder(environmentId, createResponse.getConfigurationId()).build();
    Configuration getResponse = discovery.getConfiguration(getOptions).execute();
    assertEquals(createResponse.getName(), getResponse.getName());
}
Also used : Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) GetConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetConfigurationOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 5 with Configuration

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

the class DiscoveryServiceIT method testConfigurationInEnvironmentWithAllOptionsIsSuccessful.

@Test
public void testConfigurationInEnvironmentWithAllOptionsIsSuccessful() {
    Configuration testConfig = createTestConfig();
    String myDocumentJson = "{\"field\":\"value2\"}";
    InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
    JsonObject myMetadata = new JsonObject();
    myMetadata.add("foo", new JsonPrimitive("bar"));
    TestConfigurationInEnvironmentOptions.Builder builder = new TestConfigurationInEnvironmentOptions.Builder();
    builder.environmentId(environmentId);
    builder.configurationId(testConfig.getConfigurationId());
    builder.step(TestConfigurationInEnvironmentOptions.Step.HTML_OUTPUT);
    builder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
    builder.filename("test_file");
    builder.metadata(myMetadata.toString());
    TestDocument testResponse = discovery.testConfigurationInEnvironment(builder.build()).execute();
    assertNotNull(testResponse);
    assertEquals(0, testResponse.getNotices().size());
}
Also used : TestDocument(com.ibm.watson.developer_cloud.discovery.v1.model.TestDocument) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonPrimitive(com.google.gson.JsonPrimitive) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TestConfigurationInEnvironmentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.TestConfigurationInEnvironmentOptions) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)27 Test (org.junit.Test)21 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)18 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)8 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)8 CreateConfigurationOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)5 GetConfigurationOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetConfigurationOptions)4 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)4 JsonObject (com.google.gson.JsonObject)3 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)3 ListConfigurationsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListConfigurationsOptions)3 ListConfigurationsResponse (com.ibm.watson.developer_cloud.discovery.v1.model.ListConfigurationsResponse)3 NormalizationOperation (com.ibm.watson.developer_cloud.discovery.v1.model.NormalizationOperation)3 TestDocument (com.ibm.watson.developer_cloud.discovery.v1.model.TestDocument)3 FileInputStream (java.io.FileInputStream)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Conversions (com.ibm.watson.developer_cloud.discovery.v1.model.Conversions)2 DeleteCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteCollectionOptions)2