Search in sources :

Example 1 with NormalizationOperation

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

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

the class DiscoveryTest method testCreateConfigurationWOptions.

// Test the createConfiguration operation with a valid options model parameter
@Test
public void testCreateConfigurationWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"configuration_id\": \"configurationId\", \"name\": \"name\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"description\": \"description\", \"conversions\": {\"pdf\": {\"heading\": {\"fonts\": [{\"level\": 5, \"min_size\": 7, \"max_size\": 7, \"bold\": true, \"italic\": true, \"name\": \"name\"}]}}, \"word\": {\"heading\": {\"fonts\": [{\"level\": 5, \"min_size\": 7, \"max_size\": 7, \"bold\": true, \"italic\": true, \"name\": \"name\"}], \"styles\": [{\"level\": 5, \"names\": [\"names\"]}]}}, \"html\": {\"exclude_tags_completely\": [\"excludeTagsCompletely\"], \"exclude_tags_keep_content\": [\"excludeTagsKeepContent\"], \"keep_content\": {\"xpaths\": [\"xpaths\"]}, \"exclude_content\": {\"xpaths\": [\"xpaths\"]}, \"keep_tag_attributes\": [\"keepTagAttributes\"], \"exclude_tag_attributes\": [\"excludeTagAttributes\"]}, \"segment\": {\"enabled\": false, \"selector_tags\": [\"selectorTags\"], \"annotated_fields\": [\"annotatedFields\"]}, \"json_normalizations\": [{\"operation\": \"copy\", \"source_field\": \"sourceField\", \"destination_field\": \"destinationField\"}], \"image_text_recognition\": true}, \"enrichments\": [{\"description\": \"description\", \"destination_field\": \"destinationField\", \"source_field\": \"sourceField\", \"overwrite\": false, \"enrichment\": \"enrichment\", \"ignore_downstream_errors\": false, \"options\": {\"features\": {\"keywords\": {\"sentiment\": false, \"emotion\": false, \"limit\": 5}, \"entities\": {\"sentiment\": false, \"emotion\": false, \"limit\": 5, \"mentions\": true, \"mention_types\": true, \"sentence_locations\": false, \"model\": \"model\"}, \"sentiment\": {\"document\": true, \"targets\": [\"target\"]}, \"emotion\": {\"document\": true, \"targets\": [\"target\"]}, \"categories\": {\"mapKey\": \"anyValue\"}, \"semantic_roles\": {\"entities\": true, \"keywords\": true, \"limit\": 5}, \"relations\": {\"model\": \"model\"}, \"concepts\": {\"limit\": 5}}, \"language\": \"ar\", \"model\": \"model\"}}], \"normalizations\": [{\"operation\": \"copy\", \"source_field\": \"sourceField\", \"destination_field\": \"destinationField\"}], \"source\": {\"type\": \"box\", \"credential_id\": \"credentialId\", \"schedule\": {\"enabled\": true, \"time_zone\": \"America/New_York\", \"frequency\": \"daily\"}, \"options\": {\"folders\": [{\"owner_user_id\": \"ownerUserId\", \"folder_id\": \"folderId\", \"limit\": 5}], \"objects\": [{\"name\": \"name\", \"limit\": 5}], \"site_collections\": [{\"site_collection_path\": \"siteCollectionPath\", \"limit\": 5}], \"urls\": [{\"url\": \"url\", \"limit_to_starting_hosts\": true, \"crawl_speed\": \"normal\", \"allow_untrusted_certificate\": false, \"maximum_hops\": 11, \"request_timeout\": 14, \"override_robots_txt\": false, \"blacklist\": [\"blacklist\"]}], \"buckets\": [{\"name\": \"name\", \"limit\": 5}], \"crawl_all_buckets\": false}}}";
    String createConfigurationPath = "/v1/environments/testString/configurations";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    // Construct an instance of the FontSetting model
    FontSetting fontSettingModel = new FontSetting.Builder().level(Long.valueOf("26")).minSize(Long.valueOf("26")).maxSize(Long.valueOf("26")).bold(true).italic(true).name("testString").build();
    // Construct an instance of the PdfHeadingDetection model
    PdfHeadingDetection pdfHeadingDetectionModel = new PdfHeadingDetection.Builder().fonts(new java.util.ArrayList<FontSetting>(java.util.Arrays.asList(fontSettingModel))).build();
    // Construct an instance of the PdfSettings model
    PdfSettings pdfSettingsModel = new PdfSettings.Builder().heading(pdfHeadingDetectionModel).build();
    // Construct an instance of the WordStyle model
    WordStyle wordStyleModel = new WordStyle.Builder().level(Long.valueOf("26")).names(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the WordHeadingDetection model
    WordHeadingDetection wordHeadingDetectionModel = new WordHeadingDetection.Builder().fonts(new java.util.ArrayList<FontSetting>(java.util.Arrays.asList(fontSettingModel))).styles(new java.util.ArrayList<WordStyle>(java.util.Arrays.asList(wordStyleModel))).build();
    // Construct an instance of the WordSettings model
    WordSettings wordSettingsModel = new WordSettings.Builder().heading(wordHeadingDetectionModel).build();
    // Construct an instance of the XPathPatterns model
    XPathPatterns xPathPatternsModel = new XPathPatterns.Builder().xpaths(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the HtmlSettings model
    HtmlSettings htmlSettingsModel = new HtmlSettings.Builder().excludeTagsCompletely(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).excludeTagsKeepContent(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).keepContent(xPathPatternsModel).excludeContent(xPathPatternsModel).keepTagAttributes(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).excludeTagAttributes(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the SegmentSettings model
    SegmentSettings segmentSettingsModel = new SegmentSettings.Builder().enabled(false).selectorTags(new java.util.ArrayList<String>(java.util.Arrays.asList("h1", "h2"))).annotatedFields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the NormalizationOperation model
    NormalizationOperation normalizationOperationModel = new NormalizationOperation.Builder().operation("copy").sourceField("testString").destinationField("testString").build();
    // Construct an instance of the Conversions model
    Conversions conversionsModel = new Conversions.Builder().pdf(pdfSettingsModel).word(wordSettingsModel).html(htmlSettingsModel).segment(segmentSettingsModel).jsonNormalizations(new java.util.ArrayList<NormalizationOperation>(java.util.Arrays.asList(normalizationOperationModel))).imageTextRecognition(true).build();
    // Construct an instance of the NluEnrichmentKeywords model
    NluEnrichmentKeywords nluEnrichmentKeywordsModel = new NluEnrichmentKeywords.Builder().sentiment(true).emotion(true).limit(Long.valueOf("26")).build();
    // Construct an instance of the NluEnrichmentEntities model
    NluEnrichmentEntities nluEnrichmentEntitiesModel = new NluEnrichmentEntities.Builder().sentiment(true).emotion(true).limit(Long.valueOf("26")).mentions(true).mentionTypes(true).sentenceLocations(true).model("testString").build();
    // Construct an instance of the NluEnrichmentSentiment model
    NluEnrichmentSentiment nluEnrichmentSentimentModel = new NluEnrichmentSentiment.Builder().document(true).targets(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the NluEnrichmentEmotion model
    NluEnrichmentEmotion nluEnrichmentEmotionModel = new NluEnrichmentEmotion.Builder().document(true).targets(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the NluEnrichmentSemanticRoles model
    NluEnrichmentSemanticRoles nluEnrichmentSemanticRolesModel = new NluEnrichmentSemanticRoles.Builder().entities(true).keywords(true).limit(Long.valueOf("26")).build();
    // Construct an instance of the NluEnrichmentRelations model
    NluEnrichmentRelations nluEnrichmentRelationsModel = new NluEnrichmentRelations.Builder().model("testString").build();
    // Construct an instance of the NluEnrichmentConcepts model
    NluEnrichmentConcepts nluEnrichmentConceptsModel = new NluEnrichmentConcepts.Builder().limit(Long.valueOf("26")).build();
    // Construct an instance of the NluEnrichmentFeatures model
    NluEnrichmentFeatures nluEnrichmentFeaturesModel = new NluEnrichmentFeatures.Builder().keywords(nluEnrichmentKeywordsModel).entities(nluEnrichmentEntitiesModel).sentiment(nluEnrichmentSentimentModel).emotion(nluEnrichmentEmotionModel).categories(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).semanticRoles(nluEnrichmentSemanticRolesModel).relations(nluEnrichmentRelationsModel).concepts(nluEnrichmentConceptsModel).build();
    // Construct an instance of the EnrichmentOptions model
    EnrichmentOptions enrichmentOptionsModel = new EnrichmentOptions.Builder().features(nluEnrichmentFeaturesModel).language("ar").model("testString").build();
    // Construct an instance of the Enrichment model
    Enrichment enrichmentModel = new Enrichment.Builder().description("testString").destinationField("testString").sourceField("testString").overwrite(false).enrichment("testString").ignoreDownstreamErrors(false).options(enrichmentOptionsModel).build();
    // Construct an instance of the SourceSchedule model
    SourceSchedule sourceScheduleModel = new SourceSchedule.Builder().enabled(true).timeZone("America/New_York").frequency("daily").build();
    // Construct an instance of the SourceOptionsFolder model
    SourceOptionsFolder sourceOptionsFolderModel = new SourceOptionsFolder.Builder().ownerUserId("testString").folderId("testString").limit(Long.valueOf("26")).build();
    // Construct an instance of the SourceOptionsObject model
    SourceOptionsObject sourceOptionsObjectModel = new SourceOptionsObject.Builder().name("testString").limit(Long.valueOf("26")).build();
    // Construct an instance of the SourceOptionsSiteColl model
    SourceOptionsSiteColl sourceOptionsSiteCollModel = new SourceOptionsSiteColl.Builder().siteCollectionPath("testString").limit(Long.valueOf("26")).build();
    // Construct an instance of the SourceOptionsWebCrawl model
    SourceOptionsWebCrawl sourceOptionsWebCrawlModel = new SourceOptionsWebCrawl.Builder().url("testString").limitToStartingHosts(true).crawlSpeed("normal").allowUntrustedCertificate(false).maximumHops(Long.valueOf("26")).requestTimeout(Long.valueOf("26")).overrideRobotsTxt(false).blacklist(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the SourceOptionsBuckets model
    SourceOptionsBuckets sourceOptionsBucketsModel = new SourceOptionsBuckets.Builder().name("testString").limit(Long.valueOf("26")).build();
    // Construct an instance of the SourceOptions model
    SourceOptions sourceOptionsModel = new SourceOptions.Builder().folders(new java.util.ArrayList<SourceOptionsFolder>(java.util.Arrays.asList(sourceOptionsFolderModel))).objects(new java.util.ArrayList<SourceOptionsObject>(java.util.Arrays.asList(sourceOptionsObjectModel))).siteCollections(new java.util.ArrayList<SourceOptionsSiteColl>(java.util.Arrays.asList(sourceOptionsSiteCollModel))).urls(new java.util.ArrayList<SourceOptionsWebCrawl>(java.util.Arrays.asList(sourceOptionsWebCrawlModel))).buckets(new java.util.ArrayList<SourceOptionsBuckets>(java.util.Arrays.asList(sourceOptionsBucketsModel))).crawlAllBuckets(true).build();
    // Construct an instance of the Source model
    Source sourceModel = new Source.Builder().type("box").credentialId("testString").schedule(sourceScheduleModel).options(sourceOptionsModel).build();
    // Construct an instance of the CreateConfigurationOptions model
    CreateConfigurationOptions createConfigurationOptionsModel = new CreateConfigurationOptions.Builder().environmentId("testString").name("testString").description("testString").conversions(conversionsModel).enrichments(new java.util.ArrayList<Enrichment>(java.util.Arrays.asList(enrichmentModel))).normalizations(new java.util.ArrayList<NormalizationOperation>(java.util.Arrays.asList(normalizationOperationModel))).source(sourceModel).build();
    // Invoke createConfiguration() with a valid options model and verify the result
    Response<Configuration> response = discoveryService.createConfiguration(createConfigurationOptionsModel).execute();
    assertNotNull(response);
    Configuration responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, createConfigurationPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : SourceOptionsSiteColl(com.ibm.watson.discovery.v1.model.SourceOptionsSiteColl) NluEnrichmentEntities(com.ibm.watson.discovery.v1.model.NluEnrichmentEntities) Configuration(com.ibm.watson.discovery.v1.model.Configuration) FontSetting(com.ibm.watson.discovery.v1.model.FontSetting) NluEnrichmentFeatures(com.ibm.watson.discovery.v1.model.NluEnrichmentFeatures) SourceSchedule(com.ibm.watson.discovery.v1.model.SourceSchedule) SourceOptionsObject(com.ibm.watson.discovery.v1.model.SourceOptionsObject) HtmlSettings(com.ibm.watson.discovery.v1.model.HtmlSettings) EnrichmentOptions(com.ibm.watson.discovery.v1.model.EnrichmentOptions) NluEnrichmentKeywords(com.ibm.watson.discovery.v1.model.NluEnrichmentKeywords) MockResponse(okhttp3.mockwebserver.MockResponse) SourceOptionsBuckets(com.ibm.watson.discovery.v1.model.SourceOptionsBuckets) NluEnrichmentSentiment(com.ibm.watson.discovery.v1.model.NluEnrichmentSentiment) NluEnrichmentSemanticRoles(com.ibm.watson.discovery.v1.model.NluEnrichmentSemanticRoles) SourceOptions(com.ibm.watson.discovery.v1.model.SourceOptions) Conversions(com.ibm.watson.discovery.v1.model.Conversions) WordSettings(com.ibm.watson.discovery.v1.model.WordSettings) SourceOptionsObject(com.ibm.watson.discovery.v1.model.SourceOptionsObject) Enrichment(com.ibm.watson.discovery.v1.model.Enrichment) SourceOptionsFolder(com.ibm.watson.discovery.v1.model.SourceOptionsFolder) XPathPatterns(com.ibm.watson.discovery.v1.model.XPathPatterns) NluEnrichmentConcepts(com.ibm.watson.discovery.v1.model.NluEnrichmentConcepts) Source(com.ibm.watson.discovery.v1.model.Source) NluEnrichmentRelations(com.ibm.watson.discovery.v1.model.NluEnrichmentRelations) PdfHeadingDetection(com.ibm.watson.discovery.v1.model.PdfHeadingDetection) PdfSettings(com.ibm.watson.discovery.v1.model.PdfSettings) NluEnrichmentEmotion(com.ibm.watson.discovery.v1.model.NluEnrichmentEmotion) CreateConfigurationOptions(com.ibm.watson.discovery.v1.model.CreateConfigurationOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) WordHeadingDetection(com.ibm.watson.discovery.v1.model.WordHeadingDetection) NormalizationOperation(com.ibm.watson.discovery.v1.model.NormalizationOperation) WordStyle(com.ibm.watson.discovery.v1.model.WordStyle) SegmentSettings(com.ibm.watson.discovery.v1.model.SegmentSettings) SourceOptionsWebCrawl(com.ibm.watson.discovery.v1.model.SourceOptionsWebCrawl) Test(org.testng.annotations.Test)

Example 3 with NormalizationOperation

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

the class DiscoveryTest method testUpdateConfigurationWOptions.

// Test the updateConfiguration operation with a valid options model parameter
@Test
public void testUpdateConfigurationWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"configuration_id\": \"configurationId\", \"name\": \"name\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"description\": \"description\", \"conversions\": {\"pdf\": {\"heading\": {\"fonts\": [{\"level\": 5, \"min_size\": 7, \"max_size\": 7, \"bold\": true, \"italic\": true, \"name\": \"name\"}]}}, \"word\": {\"heading\": {\"fonts\": [{\"level\": 5, \"min_size\": 7, \"max_size\": 7, \"bold\": true, \"italic\": true, \"name\": \"name\"}], \"styles\": [{\"level\": 5, \"names\": [\"names\"]}]}}, \"html\": {\"exclude_tags_completely\": [\"excludeTagsCompletely\"], \"exclude_tags_keep_content\": [\"excludeTagsKeepContent\"], \"keep_content\": {\"xpaths\": [\"xpaths\"]}, \"exclude_content\": {\"xpaths\": [\"xpaths\"]}, \"keep_tag_attributes\": [\"keepTagAttributes\"], \"exclude_tag_attributes\": [\"excludeTagAttributes\"]}, \"segment\": {\"enabled\": false, \"selector_tags\": [\"selectorTags\"], \"annotated_fields\": [\"annotatedFields\"]}, \"json_normalizations\": [{\"operation\": \"copy\", \"source_field\": \"sourceField\", \"destination_field\": \"destinationField\"}], \"image_text_recognition\": true}, \"enrichments\": [{\"description\": \"description\", \"destination_field\": \"destinationField\", \"source_field\": \"sourceField\", \"overwrite\": false, \"enrichment\": \"enrichment\", \"ignore_downstream_errors\": false, \"options\": {\"features\": {\"keywords\": {\"sentiment\": false, \"emotion\": false, \"limit\": 5}, \"entities\": {\"sentiment\": false, \"emotion\": false, \"limit\": 5, \"mentions\": true, \"mention_types\": true, \"sentence_locations\": false, \"model\": \"model\"}, \"sentiment\": {\"document\": true, \"targets\": [\"target\"]}, \"emotion\": {\"document\": true, \"targets\": [\"target\"]}, \"categories\": {\"mapKey\": \"anyValue\"}, \"semantic_roles\": {\"entities\": true, \"keywords\": true, \"limit\": 5}, \"relations\": {\"model\": \"model\"}, \"concepts\": {\"limit\": 5}}, \"language\": \"ar\", \"model\": \"model\"}}], \"normalizations\": [{\"operation\": \"copy\", \"source_field\": \"sourceField\", \"destination_field\": \"destinationField\"}], \"source\": {\"type\": \"box\", \"credential_id\": \"credentialId\", \"schedule\": {\"enabled\": true, \"time_zone\": \"America/New_York\", \"frequency\": \"daily\"}, \"options\": {\"folders\": [{\"owner_user_id\": \"ownerUserId\", \"folder_id\": \"folderId\", \"limit\": 5}], \"objects\": [{\"name\": \"name\", \"limit\": 5}], \"site_collections\": [{\"site_collection_path\": \"siteCollectionPath\", \"limit\": 5}], \"urls\": [{\"url\": \"url\", \"limit_to_starting_hosts\": true, \"crawl_speed\": \"normal\", \"allow_untrusted_certificate\": false, \"maximum_hops\": 11, \"request_timeout\": 14, \"override_robots_txt\": false, \"blacklist\": [\"blacklist\"]}], \"buckets\": [{\"name\": \"name\", \"limit\": 5}], \"crawl_all_buckets\": false}}}";
    String updateConfigurationPath = "/v1/environments/testString/configurations/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the FontSetting model
    FontSetting fontSettingModel = new FontSetting.Builder().level(Long.valueOf("26")).minSize(Long.valueOf("26")).maxSize(Long.valueOf("26")).bold(true).italic(true).name("testString").build();
    // Construct an instance of the PdfHeadingDetection model
    PdfHeadingDetection pdfHeadingDetectionModel = new PdfHeadingDetection.Builder().fonts(new java.util.ArrayList<FontSetting>(java.util.Arrays.asList(fontSettingModel))).build();
    // Construct an instance of the PdfSettings model
    PdfSettings pdfSettingsModel = new PdfSettings.Builder().heading(pdfHeadingDetectionModel).build();
    // Construct an instance of the WordStyle model
    WordStyle wordStyleModel = new WordStyle.Builder().level(Long.valueOf("26")).names(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the WordHeadingDetection model
    WordHeadingDetection wordHeadingDetectionModel = new WordHeadingDetection.Builder().fonts(new java.util.ArrayList<FontSetting>(java.util.Arrays.asList(fontSettingModel))).styles(new java.util.ArrayList<WordStyle>(java.util.Arrays.asList(wordStyleModel))).build();
    // Construct an instance of the WordSettings model
    WordSettings wordSettingsModel = new WordSettings.Builder().heading(wordHeadingDetectionModel).build();
    // Construct an instance of the XPathPatterns model
    XPathPatterns xPathPatternsModel = new XPathPatterns.Builder().xpaths(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the HtmlSettings model
    HtmlSettings htmlSettingsModel = new HtmlSettings.Builder().excludeTagsCompletely(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).excludeTagsKeepContent(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).keepContent(xPathPatternsModel).excludeContent(xPathPatternsModel).keepTagAttributes(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).excludeTagAttributes(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the SegmentSettings model
    SegmentSettings segmentSettingsModel = new SegmentSettings.Builder().enabled(false).selectorTags(new java.util.ArrayList<String>(java.util.Arrays.asList("h1", "h2"))).annotatedFields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the NormalizationOperation model
    NormalizationOperation normalizationOperationModel = new NormalizationOperation.Builder().operation("copy").sourceField("testString").destinationField("testString").build();
    // Construct an instance of the Conversions model
    Conversions conversionsModel = new Conversions.Builder().pdf(pdfSettingsModel).word(wordSettingsModel).html(htmlSettingsModel).segment(segmentSettingsModel).jsonNormalizations(new java.util.ArrayList<NormalizationOperation>(java.util.Arrays.asList(normalizationOperationModel))).imageTextRecognition(true).build();
    // Construct an instance of the NluEnrichmentKeywords model
    NluEnrichmentKeywords nluEnrichmentKeywordsModel = new NluEnrichmentKeywords.Builder().sentiment(true).emotion(true).limit(Long.valueOf("26")).build();
    // Construct an instance of the NluEnrichmentEntities model
    NluEnrichmentEntities nluEnrichmentEntitiesModel = new NluEnrichmentEntities.Builder().sentiment(true).emotion(true).limit(Long.valueOf("26")).mentions(true).mentionTypes(true).sentenceLocations(true).model("testString").build();
    // Construct an instance of the NluEnrichmentSentiment model
    NluEnrichmentSentiment nluEnrichmentSentimentModel = new NluEnrichmentSentiment.Builder().document(true).targets(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the NluEnrichmentEmotion model
    NluEnrichmentEmotion nluEnrichmentEmotionModel = new NluEnrichmentEmotion.Builder().document(true).targets(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the NluEnrichmentSemanticRoles model
    NluEnrichmentSemanticRoles nluEnrichmentSemanticRolesModel = new NluEnrichmentSemanticRoles.Builder().entities(true).keywords(true).limit(Long.valueOf("26")).build();
    // Construct an instance of the NluEnrichmentRelations model
    NluEnrichmentRelations nluEnrichmentRelationsModel = new NluEnrichmentRelations.Builder().model("testString").build();
    // Construct an instance of the NluEnrichmentConcepts model
    NluEnrichmentConcepts nluEnrichmentConceptsModel = new NluEnrichmentConcepts.Builder().limit(Long.valueOf("26")).build();
    // Construct an instance of the NluEnrichmentFeatures model
    NluEnrichmentFeatures nluEnrichmentFeaturesModel = new NluEnrichmentFeatures.Builder().keywords(nluEnrichmentKeywordsModel).entities(nluEnrichmentEntitiesModel).sentiment(nluEnrichmentSentimentModel).emotion(nluEnrichmentEmotionModel).categories(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).semanticRoles(nluEnrichmentSemanticRolesModel).relations(nluEnrichmentRelationsModel).concepts(nluEnrichmentConceptsModel).build();
    // Construct an instance of the EnrichmentOptions model
    EnrichmentOptions enrichmentOptionsModel = new EnrichmentOptions.Builder().features(nluEnrichmentFeaturesModel).language("ar").model("testString").build();
    // Construct an instance of the Enrichment model
    Enrichment enrichmentModel = new Enrichment.Builder().description("testString").destinationField("testString").sourceField("testString").overwrite(false).enrichment("testString").ignoreDownstreamErrors(false).options(enrichmentOptionsModel).build();
    // Construct an instance of the SourceSchedule model
    SourceSchedule sourceScheduleModel = new SourceSchedule.Builder().enabled(true).timeZone("America/New_York").frequency("daily").build();
    // Construct an instance of the SourceOptionsFolder model
    SourceOptionsFolder sourceOptionsFolderModel = new SourceOptionsFolder.Builder().ownerUserId("testString").folderId("testString").limit(Long.valueOf("26")).build();
    // Construct an instance of the SourceOptionsObject model
    SourceOptionsObject sourceOptionsObjectModel = new SourceOptionsObject.Builder().name("testString").limit(Long.valueOf("26")).build();
    // Construct an instance of the SourceOptionsSiteColl model
    SourceOptionsSiteColl sourceOptionsSiteCollModel = new SourceOptionsSiteColl.Builder().siteCollectionPath("testString").limit(Long.valueOf("26")).build();
    // Construct an instance of the SourceOptionsWebCrawl model
    SourceOptionsWebCrawl sourceOptionsWebCrawlModel = new SourceOptionsWebCrawl.Builder().url("testString").limitToStartingHosts(true).crawlSpeed("normal").allowUntrustedCertificate(false).maximumHops(Long.valueOf("26")).requestTimeout(Long.valueOf("26")).overrideRobotsTxt(false).blacklist(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the SourceOptionsBuckets model
    SourceOptionsBuckets sourceOptionsBucketsModel = new SourceOptionsBuckets.Builder().name("testString").limit(Long.valueOf("26")).build();
    // Construct an instance of the SourceOptions model
    SourceOptions sourceOptionsModel = new SourceOptions.Builder().folders(new java.util.ArrayList<SourceOptionsFolder>(java.util.Arrays.asList(sourceOptionsFolderModel))).objects(new java.util.ArrayList<SourceOptionsObject>(java.util.Arrays.asList(sourceOptionsObjectModel))).siteCollections(new java.util.ArrayList<SourceOptionsSiteColl>(java.util.Arrays.asList(sourceOptionsSiteCollModel))).urls(new java.util.ArrayList<SourceOptionsWebCrawl>(java.util.Arrays.asList(sourceOptionsWebCrawlModel))).buckets(new java.util.ArrayList<SourceOptionsBuckets>(java.util.Arrays.asList(sourceOptionsBucketsModel))).crawlAllBuckets(true).build();
    // Construct an instance of the Source model
    Source sourceModel = new Source.Builder().type("box").credentialId("testString").schedule(sourceScheduleModel).options(sourceOptionsModel).build();
    // Construct an instance of the UpdateConfigurationOptions model
    UpdateConfigurationOptions updateConfigurationOptionsModel = new UpdateConfigurationOptions.Builder().environmentId("testString").configurationId("testString").name("testString").description("testString").conversions(conversionsModel).enrichments(new java.util.ArrayList<Enrichment>(java.util.Arrays.asList(enrichmentModel))).normalizations(new java.util.ArrayList<NormalizationOperation>(java.util.Arrays.asList(normalizationOperationModel))).source(sourceModel).build();
    // Invoke updateConfiguration() with a valid options model and verify the result
    Response<Configuration> response = discoveryService.updateConfiguration(updateConfigurationOptionsModel).execute();
    assertNotNull(response);
    Configuration responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "PUT");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, updateConfigurationPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
}
Also used : SourceOptionsSiteColl(com.ibm.watson.discovery.v1.model.SourceOptionsSiteColl) NluEnrichmentEntities(com.ibm.watson.discovery.v1.model.NluEnrichmentEntities) Configuration(com.ibm.watson.discovery.v1.model.Configuration) FontSetting(com.ibm.watson.discovery.v1.model.FontSetting) NluEnrichmentFeatures(com.ibm.watson.discovery.v1.model.NluEnrichmentFeatures) SourceSchedule(com.ibm.watson.discovery.v1.model.SourceSchedule) SourceOptionsObject(com.ibm.watson.discovery.v1.model.SourceOptionsObject) HtmlSettings(com.ibm.watson.discovery.v1.model.HtmlSettings) EnrichmentOptions(com.ibm.watson.discovery.v1.model.EnrichmentOptions) UpdateConfigurationOptions(com.ibm.watson.discovery.v1.model.UpdateConfigurationOptions) NluEnrichmentKeywords(com.ibm.watson.discovery.v1.model.NluEnrichmentKeywords) MockResponse(okhttp3.mockwebserver.MockResponse) SourceOptionsBuckets(com.ibm.watson.discovery.v1.model.SourceOptionsBuckets) NluEnrichmentSentiment(com.ibm.watson.discovery.v1.model.NluEnrichmentSentiment) NluEnrichmentSemanticRoles(com.ibm.watson.discovery.v1.model.NluEnrichmentSemanticRoles) SourceOptions(com.ibm.watson.discovery.v1.model.SourceOptions) Conversions(com.ibm.watson.discovery.v1.model.Conversions) WordSettings(com.ibm.watson.discovery.v1.model.WordSettings) SourceOptionsObject(com.ibm.watson.discovery.v1.model.SourceOptionsObject) Enrichment(com.ibm.watson.discovery.v1.model.Enrichment) SourceOptionsFolder(com.ibm.watson.discovery.v1.model.SourceOptionsFolder) XPathPatterns(com.ibm.watson.discovery.v1.model.XPathPatterns) NluEnrichmentConcepts(com.ibm.watson.discovery.v1.model.NluEnrichmentConcepts) Source(com.ibm.watson.discovery.v1.model.Source) NluEnrichmentRelations(com.ibm.watson.discovery.v1.model.NluEnrichmentRelations) PdfHeadingDetection(com.ibm.watson.discovery.v1.model.PdfHeadingDetection) PdfSettings(com.ibm.watson.discovery.v1.model.PdfSettings) NluEnrichmentEmotion(com.ibm.watson.discovery.v1.model.NluEnrichmentEmotion) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) WordHeadingDetection(com.ibm.watson.discovery.v1.model.WordHeadingDetection) NormalizationOperation(com.ibm.watson.discovery.v1.model.NormalizationOperation) WordStyle(com.ibm.watson.discovery.v1.model.WordStyle) SegmentSettings(com.ibm.watson.discovery.v1.model.SegmentSettings) SourceOptionsWebCrawl(com.ibm.watson.discovery.v1.model.SourceOptionsWebCrawl) Test(org.testng.annotations.Test)

Example 4 with NormalizationOperation

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

the class DiscoveryServiceTest method testCreateConfigurationOptions.

/**
 * Test create configuration options.
 */
// Configuration tests
@Test
public void testCreateConfigurationOptions() {
    String name = "name";
    String description = "description";
    Conversions conversions = new Conversions.Builder().build();
    String firstEnrichmentName = "first";
    String secondEnrichmentName = "second";
    String sourceField = "source_field";
    String destinationField = "destination_field";
    List<Enrichment> enrichments = new ArrayList<>();
    Enrichment firstEnrichment = new Enrichment.Builder().enrichment(firstEnrichmentName).sourceField(sourceField).destinationField(destinationField).build();
    enrichments.add(firstEnrichment);
    Enrichment secondEnrichment = new Enrichment.Builder().enrichment(secondEnrichmentName).sourceField(sourceField).destinationField(destinationField).build();
    List<NormalizationOperation> normalizationOperations = new ArrayList<>();
    NormalizationOperation firstOp = new NormalizationOperation.Builder().operation(NormalizationOperation.Operation.MERGE).build();
    NormalizationOperation secondOp = new NormalizationOperation.Builder().operation(NormalizationOperation.Operation.COPY).build();
    normalizationOperations.add(firstOp);
    Source source = new Source.Builder().build();
    CreateConfigurationOptions createConfigurationOptions = new CreateConfigurationOptions.Builder().environmentId(environmentId).name(name).description(description).conversions(conversions).enrichments(enrichments).addEnrichment(secondEnrichment).normalizations(normalizationOperations).addNormalization(secondOp).source(source).build();
    createConfigurationOptions = createConfigurationOptions.newBuilder().build();
    enrichments.add(secondEnrichment);
    normalizationOperations.add(secondOp);
    assertEquals(environmentId, createConfigurationOptions.environmentId());
    assertEquals(name, createConfigurationOptions.name());
    assertEquals(description, createConfigurationOptions.description());
    assertEquals(conversions, createConfigurationOptions.conversions());
    assertEquals(enrichments, createConfigurationOptions.enrichments());
    assertEquals(normalizationOperations, createConfigurationOptions.normalizations());
    assertEquals(source, createConfigurationOptions.source());
}
Also used : Enrichment(com.ibm.watson.discovery.v1.model.Enrichment) CreateConfigurationOptions(com.ibm.watson.discovery.v1.model.CreateConfigurationOptions) Conversions(com.ibm.watson.discovery.v1.model.Conversions) NormalizationOperation(com.ibm.watson.discovery.v1.model.NormalizationOperation) ArrayList(java.util.ArrayList) Source(com.ibm.watson.discovery.v1.model.Source) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Example 5 with NormalizationOperation

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

Aggregations

WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)3 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)3 Conversions (com.ibm.watson.discovery.v1.model.Conversions)3 Enrichment (com.ibm.watson.discovery.v1.model.Enrichment)3 NormalizationOperation (com.ibm.watson.discovery.v1.model.NormalizationOperation)3 Source (com.ibm.watson.discovery.v1.model.Source)3 Conversions (com.ibm.watson.developer_cloud.discovery.v1.model.Conversions)2 CreateConfigurationOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateConfigurationOptions)2 Enrichment (com.ibm.watson.developer_cloud.discovery.v1.model.Enrichment)2 NormalizationOperation (com.ibm.watson.developer_cloud.discovery.v1.model.NormalizationOperation)2 Configuration (com.ibm.watson.discovery.v1.model.Configuration)2 CreateConfigurationOptions (com.ibm.watson.discovery.v1.model.CreateConfigurationOptions)2 EnrichmentOptions (com.ibm.watson.discovery.v1.model.EnrichmentOptions)2 FontSetting (com.ibm.watson.discovery.v1.model.FontSetting)2 HtmlSettings (com.ibm.watson.discovery.v1.model.HtmlSettings)2 NluEnrichmentConcepts (com.ibm.watson.discovery.v1.model.NluEnrichmentConcepts)2 NluEnrichmentEmotion (com.ibm.watson.discovery.v1.model.NluEnrichmentEmotion)2 NluEnrichmentEntities (com.ibm.watson.discovery.v1.model.NluEnrichmentEntities)2 NluEnrichmentFeatures (com.ibm.watson.discovery.v1.model.NluEnrichmentFeatures)2 NluEnrichmentKeywords (com.ibm.watson.discovery.v1.model.NluEnrichmentKeywords)2