Search in sources :

Example 16 with Configuration

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

the class DiscoveryServiceIT method createCollectionIsSuccessful.

@Test
public void createCollectionIsSuccessful() {
    Configuration createConfigResponse = createTestConfig();
    String uniqueCollectionName = uniqueName + "-collection";
    String uniqueCollectionDescription = "Description of " + uniqueCollectionName;
    CreateCollectionOptions.Builder createCollectionBuilder = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).configurationId(createConfigResponse.getConfigurationId()).description(uniqueCollectionDescription);
    Collection createResponse = createCollection(createCollectionBuilder.build());
    assertEquals(createConfigResponse.getConfigurationId(), createResponse.getConfigurationId());
    assertEquals(uniqueCollectionName, createResponse.getName());
    assertEquals(uniqueCollectionDescription, createResponse.getDescription());
}
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) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 17 with Configuration

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

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

the class DiscoveryServiceIT method issueNumber518.

@Test
public void issueNumber518() {
    String[] operations = new String[] { Operation.MOVE, Operation.COPY, Operation.MERGE, Operation.REMOVE, Operation.REMOVE_NULLS };
    String uniqueConfigName = uniqueName + "-config";
    CreateConfigurationOptions.Builder createBuilder = new CreateConfigurationOptions.Builder(environmentId);
    Configuration configuration = getTestConfiguration(DISCOVERY2_TEST_CONFIG_FILE);
    configuration.setName(uniqueConfigName);
    createBuilder.configuration(configuration);
    Configuration createResponse = createConfiguration(createBuilder.build());
    GetConfigurationOptions getOptions = new GetConfigurationOptions.Builder(environmentId, createResponse.getConfigurationId()).build();
    Configuration getResponse = discovery.getConfiguration(getOptions).execute();
    // verify getResponse deserializes the operations appropriately
    for (NormalizationOperation normalization : getResponse.getNormalizations()) {
        String operation = normalization.getOperation();
        assertEquals(true, Arrays.asList(operations).contains(operation));
    }
}
Also used : CreateConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) GetConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetConfigurationOptions) NormalizationOperation(com.ibm.watson.developer_cloud.discovery.v1.model.NormalizationOperation) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 19 with Configuration

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

the class DiscoveryServiceTest method createConfigurationIsSuccessful.

// Configuration tests
@Test
public void createConfigurationIsSuccessful() throws JsonSyntaxException, JsonIOException, FileNotFoundException, InterruptedException {
    server.enqueue(jsonResponse(createConfResp));
    CreateConfigurationOptions.Builder createBuilder = new CreateConfigurationOptions.Builder(environmentId);
    Configuration configuration = GsonSingleton.getGson().fromJson(new FileReader(DISCOVERY_TEST_CONFIG_FILE), Configuration.class);
    createBuilder.configuration(configuration);
    createBuilder.name(uniqueConfigName);
    Configuration response = discoveryService.createConfiguration(createBuilder.build()).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(CONF1_PATH, request.getPath());
    assertEquals(POST, request.getMethod());
    assertEquals(createConfResp, response);
}
Also used : CreateConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) FileReader(java.io.FileReader) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 20 with Configuration

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

the class DiscoveryServiceTest method updateConfigurationIsSuccessful.

@Test
public void updateConfigurationIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(updateConfResp));
    UpdateConfigurationOptions.Builder updateBuilder = new UpdateConfigurationOptions.Builder(environmentId, configurationId);
    Configuration newConf = new Configuration();
    newConf.setName("newName");
    updateBuilder.configuration(newConf);
    Configuration response = discoveryService.updateConfiguration(updateBuilder.build()).execute();
    RecordedRequest request = server.takeRequest();
    assertEquals(CONF2_PATH, request.getPath());
    assertEquals(PUT, request.getMethod());
    assertEquals(updateConfResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) UpdateConfigurationOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateConfigurationOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

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