From f164e370a53a0553d1030d4a01043400e0224db0 Mon Sep 17 00:00:00 2001 From: Logan Patino Date: Fri, 30 Mar 2018 13:51:31 -0400 Subject: [PATCH 01/12] refactor(examples): Remove deprecated examples and update SDK version --- examples/build.gradle | 2 +- .../build.gradle | 2 +- .../v1/GetNewsDocumentExample.java | 57 ------- .../v1/GetVolumeExample.java | 35 ----- .../v1/AlchemyLanguageExample.java | 47 ------ .../v1/ImageKeywordsExample.java | 33 ---- .../v1/RecognizeFacesExample.java | 33 ---- .../dialog/v1/DialogServiceExample.java | 74 --------- ...DocumentConversionCustomConfigExample.java | 83 ----------- .../v1/DocumentConversionExample.java | 45 ------ ...ocumentConversionIndexDocumentExample.java | 141 ------------------ .../v2/PersonalityInsightsExample.java | 40 ----- .../v1/CreateARankerExample.java | 50 ------- .../v1/CreateASolrClusterExample.java | 45 ------ .../v1/ResizeASolrClusterExample.java | 58 ------- .../v1/UploadSolrConfigurationExample.java | 45 ------ .../v1/TradeoffAnalyticsExample.java | 73 --------- 17 files changed, 2 insertions(+), 861 deletions(-) delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_data_news/v1/GetNewsDocumentExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_data_news/v1/GetVolumeExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_language/v1/AlchemyLanguageExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_vision/v1/ImageKeywordsExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_vision/v1/RecognizeFacesExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/dialog/v1/DialogServiceExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionCustomConfigExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionIndexDocumentExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/personality_insights/v2/PersonalityInsightsExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/CreateARankerExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/CreateASolrClusterExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/ResizeASolrClusterExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/UploadSolrConfigurationExample.java delete mode 100644 examples/src/main/java/com/ibm/watson/developer_cloud/tradeoff_analytics/v1/TradeoffAnalyticsExample.java diff --git a/examples/build.gradle b/examples/build.gradle index 6c78533e37a..a683a0af5b4 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -33,5 +33,5 @@ checkstyle { } dependencies { - compile group: 'com.ibm.watson.developer_cloud', name: 'java-sdk', version: '3.7.2' + compile group: 'com.ibm.watson.developer_cloud', name: 'java-sdk', version: '5.1.1' } diff --git a/examples/conversation_tone_analyzer_integration/build.gradle b/examples/conversation_tone_analyzer_integration/build.gradle index abd84df1e77..39ca046d8f9 100644 --- a/examples/conversation_tone_analyzer_integration/build.gradle +++ b/examples/conversation_tone_analyzer_integration/build.gradle @@ -23,6 +23,6 @@ sourceCompatibility = 1.7 targetCompatibility = 1.7 dependencies { - compile "com.ibm.watson.developer_cloud:java-sdk:3.5.0" + compile "com.ibm.watson.developer_cloud:java-sdk:5.1.1" compile "commons-io:commons-io:2.4" } \ No newline at end of file diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_data_news/v1/GetNewsDocumentExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_data_news/v1/GetNewsDocumentExample.java deleted file mode 100644 index 1034a5621c1..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_data_news/v1/GetNewsDocumentExample.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.alchemy_data_news.v1; - - -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; - -import com.ibm.watson.developer_cloud.alchemy.v1.AlchemyDataNews; -import com.ibm.watson.developer_cloud.alchemy.v1.model.DocumentsResult; - - -/** - * Getting 7 documents between Friday 28th August 2015 and Friday 4th September 2015 using the {@link AlchemyDataNews} - * API. - * - * Example from java-sdk: https://github.com/watson-developer-cloud/java-sdk - */ -public class GetNewsDocumentExample { - - public static void main(String[] args) { - AlchemyDataNews service = new AlchemyDataNews(); - service.setApiKey(""); - - Map params = new HashMap(); - - String[] fields = - new String[] { "enriched.url.title", "enriched.url.url", "enriched.url.author", "enriched.url.publicationDate", - "enriched.url.enrichedTitle.entities", "enriched.url.enrichedTitle.docSentiment"}; - params.put(AlchemyDataNews.RETURN, StringUtils.join(fields, ",")); - params.put(AlchemyDataNews.START, "1440720000"); - params.put(AlchemyDataNews.END, "1441407600"); - params.put(AlchemyDataNews.COUNT, 7); - - // Query on adjacent nested fields: - params.put("q.enriched.url.enrichedTitle.entities.entity", "|text=IBM,type=company|"); - params.put("q.enriched.url.enrichedTitle.docSentiment.type", "positive"); - params.put("q.enriched.url.enrichedTitle.taxonomy.taxonomy_.label", "technology and computing"); - - DocumentsResult result = service.getNewsDocuments(params).execute(); - - System.out.println(result); - } - -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_data_news/v1/GetVolumeExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_data_news/v1/GetVolumeExample.java deleted file mode 100644 index c6a02ea18c7..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_data_news/v1/GetVolumeExample.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.alchemy_data_news.v1; - - -import com.ibm.watson.developer_cloud.alchemy.v1.AlchemyDataNews; -import com.ibm.watson.developer_cloud.alchemy.v1.model.VolumeResult; - -/** - * Getting The number for ingested documents in the last 7 days with a 12 hour period using the {@link AlchemyDataNews} - * API. - * - */ -public class GetVolumeExample { - - public static void main(String[] args) { - AlchemyDataNews service = new AlchemyDataNews(); - service.setApiKey(""); - - VolumeResult result = service.getVolume("now-7d", "now", "12h").execute(); - - System.out.println(result); - } - -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_language/v1/AlchemyLanguageExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_language/v1/AlchemyLanguageExample.java deleted file mode 100644 index 06d6e68b1a5..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_language/v1/AlchemyLanguageExample.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.alchemy_language.v1; - - -import java.util.HashMap; -import java.util.Map; - -import com.ibm.watson.developer_cloud.alchemy.v1.AlchemyLanguage; -import com.ibm.watson.developer_cloud.alchemy.v1.model.DocumentSentiment; -import com.ibm.watson.developer_cloud.alchemy.v1.model.Entities; -import com.ibm.watson.developer_cloud.alchemy.v1.model.TypedRelations; - -public class AlchemyLanguageExample { - - public static void main(String[] args) { - AlchemyLanguage service = new AlchemyLanguage(); - service.setApiKey(""); - - Map params = new HashMap(); - params.put(AlchemyLanguage.TEXT, "IBM Watson won the Jeopardy television show hosted by Alex Trebek"); - - // get sentiment - DocumentSentiment sentiment = service.getSentiment(params).execute(); - System.out.println("Sentiment: " + sentiment); - - // get entities - Entities entities = service.getEntities(params).execute(); - System.out.println("Entities: " + entities); - - // get typed relations - TypedRelations relations = service.getTypedRelations(params).execute(); - System.out.println("Relations: " + relations); - - } - -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_vision/v1/ImageKeywordsExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_vision/v1/ImageKeywordsExample.java deleted file mode 100644 index ba9d2e7454a..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_vision/v1/ImageKeywordsExample.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.alchemy_vision.v1; - - -import java.io.File; - -import com.ibm.watson.developer_cloud.alchemy.v1.AlchemyVision; -import com.ibm.watson.developer_cloud.alchemy.v1.model.ImageKeywords; - -public class ImageKeywordsExample { - - public static void main(String[] args) { - AlchemyVision service = new AlchemyVision(); - service.setApiKey(""); - - File image = new File("src/test/resources/alchemy/obama.jpg"); - ImageKeywords keywords = service.getImageKeywords(image, true, true).execute(); - - System.out.println(keywords); - } - -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_vision/v1/RecognizeFacesExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_vision/v1/RecognizeFacesExample.java deleted file mode 100644 index b9b444c3664..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/alchemy_vision/v1/RecognizeFacesExample.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.alchemy_vision.v1; - - -import java.io.File; - -import com.ibm.watson.developer_cloud.alchemy.v1.AlchemyVision; -import com.ibm.watson.developer_cloud.alchemy.v1.model.ImageFaces; - -public class RecognizeFacesExample { - - public static void main(String[] args) { - AlchemyVision service = new AlchemyVision(); - service.setApiKey(""); - - File image = new File("src/test/resources/alchemy/obama.jpg"); - ImageFaces faces = service.recognizeFaces(image, true).execute(); - - System.out.println(faces); - } - -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/dialog/v1/DialogServiceExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/dialog/v1/DialogServiceExample.java deleted file mode 100644 index bb8bd5efe6d..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/dialog/v1/DialogServiceExample.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.dialog.v1; - -import java.util.List; - -import com.ibm.watson.developer_cloud.dialog.v1.model.Dialog; -import com.ibm.watson.developer_cloud.http.ServiceCallback; - -import jersey.repackaged.jsr166e.CompletableFuture; - -public class DialogServiceExample { - public static void main(String[] args) throws Exception { - DialogService service = new DialogService(); - service.setUsernameAndPassword("", ""); - - // sync - List dialogs = service.getDialogs().execute(); - System.out.println(dialogs); - - - // async - service.getDialogs().enqueue(new ServiceCallback>() { - @Override - public void onResponse(List response) { - System.out.println(response); - } - - @Override - public void onFailure(Exception e) { } - }); - - // rx callback - service.getDialogs().rx().thenApply(new CompletableFuture.Fun, Integer>() { - @Override - public Integer apply(List dialogs) { - return dialogs.size(); - } - }).thenAccept(new CompletableFuture.Action() { - @Override - public void accept(Integer integer) { - System.out.println(integer); - } - }); - - // rx async callback - service.getDialogs().rx().thenApplyAsync(new CompletableFuture.Fun, Integer>() { - @Override - public Integer apply(List dialogs) { - return dialogs.size(); - } - }).thenAccept(new CompletableFuture.Action() { - @Override - public void accept(Integer size) { - System.out.println(size); - } - }); - - // rx sync - Integer size = service.getDialogs().rx().get().size(); - System.out.println(size); - } - -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionCustomConfigExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionCustomConfigExample.java deleted file mode 100644 index 559df7c603c..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionCustomConfigExample.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.document_conversion.v1; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.ibm.watson.developer_cloud.document_conversion.v1.model.Answers; -import com.ibm.watson.developer_cloud.document_conversion.v1.util.ConversionUtils; -import com.ibm.watson.developer_cloud.http.HttpMediaType; - -public class DocumentConversionCustomConfigExample { - public static void main(String[] args) { - final String versionDate = "2015-12-14"; - DocumentConversion service = new DocumentConversion(versionDate); - service.setUsernameAndPassword("", ""); - - final File html = new File("src/test/resources/document_conversion/html-with-extra-content-input.htm"); - - // Run a conversion with no configuration specified. The Document Conversion service will use - // its default configuration when no configuration is specified. For this example, the - // Document Conversion service will section a HTML document by h1, h2, h3, h4, h5, and h6 tags. - // Those sections will be returned as Answers - System.out.println("Convert html document to Answer Units using default configuration"); - final Answers htmlToAnswersWithDefaultConfig = - service.convertDocumentToAnswer(html, HttpMediaType.TEXT_HTML).execute(); - System.out.println(htmlToAnswersWithDefaultConfig); - - System.out.println("=================================================="); - - // Run a conversion with a custom configuration. The next example shows how to convert this same - // document with a custom configuration. Instead of sectioning by the default settings (h1, h2, - // h3, h4, h5, and h6), the following example shows how to section a HTML document by only the - // h1 tag. This will result in Answers that are sectioned by h1 tags. - String configAsString = - "{\n" + " \"answer_units\": {\n" + " \"selector_tags\": [\"h1\"]\n" + " }\n" + "}"; - JsonParser jsonParser = new JsonParser(); - JsonObject customConfig = jsonParser.parse(configAsString).getAsJsonObject(); - - System.out.println("Convert html document to Answer Units using custom configuration"); - final Answers htmlToAnswersWithCustomConfig = - service.convertDocumentToAnswer(html, HttpMediaType.TEXT_HTML, customConfig).execute(); - System.out.println(htmlToAnswersWithCustomConfig); - - System.out.println("=================================================="); - - // Run a conversion with a custom configuration that is loaded from a file. This example is - // similar - // to the previous one above. The custom configuration from the file will section a HTML - // document - // by only the h2 tag. This will result in Answers that are sectioned by h2 tags. - System.out.println("Convert html document to Answer Units using custom configuration loaded from a file"); - String customConfigFilePath = "src/test/resources/document_conversion/answer_unit_config_selector_h2.json"; - JsonObject customConfigFromFile = null; - try { - customConfigFromFile = ConversionUtils.loadCustomConfig(new FileInputStream(customConfigFilePath)); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - - if (customConfigFromFile == null) { - System.err.println("ERROR - Unable to load custom config from file " + customConfigFilePath); - return; - } - - final Answers htmlToAnswersWithCustomConfigFromFile = - service.convertDocumentToAnswer(html, HttpMediaType.TEXT_HTML, customConfigFromFile).execute(); - System.out.println(htmlToAnswersWithCustomConfigFromFile); - } -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionExample.java deleted file mode 100644 index 6dfba516a4f..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionExample.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.document_conversion.v1; - -import java.io.File; - -import com.ibm.watson.developer_cloud.document_conversion.v1.model.Answers; - -/** - * Example class that shows the various usage scenario's of the Document Conversion service. - */ -public class DocumentConversionExample { - - public static void main(String[] args) { - DocumentConversion service = new DocumentConversion(DocumentConversion.VERSION_DATE_2015_12_01); - service.setUsernameAndPassword("", ""); - - File html = new File("src/test/resources/document_conversion/html-with-extra-content-input.htm"); - File pdf = new File("src/test/resources/document_conversion/pdf-with-sections-input.pdf"); - File doc = new File("src/test/resources/document_conversion/word-document-heading-input.doc"); - - System.out.println("Convert html document to Answers"); - Answers htmlToAnswers = service.convertDocumentToAnswer(html).execute(); - System.out.println(htmlToAnswers); - - System.out.println("Convert pdf document to Normalized HTML"); - String normalizedHTML = service.convertDocumentToHTML(pdf).execute(); - System.out.println(normalizedHTML); - - System.out.println("Convert html document to Normalized Text"); - String normalizedText = service.convertDocumentToText(doc).execute(); - System.out.println(normalizedText); - - } -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionIndexDocumentExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionIndexDocumentExample.java deleted file mode 100644 index 6f8592fd36c..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/document_conversion/v1/DocumentConversionIndexDocumentExample.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.document_conversion.v1; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; - -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.ibm.watson.developer_cloud.document_conversion.v1.model.IndexConfiguration; -import com.ibm.watson.developer_cloud.document_conversion.v1.model.IndexDocumentOptions; -import com.ibm.watson.developer_cloud.document_conversion.v1.model.IndexFields; -import com.ibm.watson.developer_cloud.http.HttpMediaType; - -/** - * Example class that shows the index document usage of the Document Conversion service. - */ -public class DocumentConversionIndexDocumentExample { - - public static void main(String[] args) { - DocumentConversion service = new DocumentConversion(DocumentConversion.VERSION_DATE_2015_12_01); - service.setUsernameAndPassword("", ""); - - // ----- Global Values ----- - IndexConfiguration indexConfiguration = - new IndexConfiguration("", "", ""); - - // Create an index configuration with the fields object (field mappings, fields to include, fields to exclude) - IndexFields fields = new IndexFields.Builder().mappings("Author", "Created By") - .mappings("Date Created", "Created On").include("SomeMetadataName").include("id").include("Created By") - .include("Created On").exclude("Category").build(); - IndexConfiguration indexConfigurationWithFields = - new IndexConfiguration("", "", "", fields); - - // Create some metadata for indexing - final Map metadata = new HashMap(); - metadata.put("id", "1"); - metadata.put("SomeMetadataName", "SomeMetadataValue"); - - // Create a convert document configuration that will exclude all anchor tags () from the input HTML file - String convertDocumentConfigAsString = "{ \"normalized_html\" : { \"exclude_tags_completely\":[\"a\"] } }"; - JsonParser jsonParser = new JsonParser(); - JsonObject convertDocumentConfig = jsonParser.parse(convertDocumentConfigAsString).getAsJsonObject(); - - // Sample file to index - File document = new File("src/test/resources/document_conversion/html-with-extra-content-input.htm"); - String html = "Sample HTML

Intro

Some content!

"; - InputStream documentInputStream = new ByteArrayInputStream(html.getBytes()); - - // ----- Examples for performing a dry run of the index document API ----- - printHeaderForExample("Dry run for indexing a document"); - IndexDocumentOptions indexDocumentOptions1 = - new IndexDocumentOptions.Builder().document(document).dryRun(true).build(); - String indexDocumentDryRun = service.indexDocument(indexDocumentOptions1).execute(); - System.out.println(indexDocumentDryRun); - - printHeaderForExample("Dry run for indexing a document (using input stream)"); - IndexDocumentOptions indexDocumentOptions2 = - new IndexDocumentOptions.Builder().document(documentInputStream, HttpMediaType.TEXT_HTML).dryRun(true).build(); - String indexDocumentInputStreamDryRun = service.indexDocument(indexDocumentOptions2).execute(); - System.out.println(indexDocumentInputStreamDryRun); - - printHeaderForExample("Dry run for indexing metadata"); - IndexDocumentOptions indexDocumentOptions3 = - new IndexDocumentOptions.Builder().metadata(metadata).dryRun(true).build(); - String indexMetadataDryRun = service.indexDocument(indexDocumentOptions3).execute(); - System.out.println(indexMetadataDryRun); - - printHeaderForExample("Dry run for indexing document and metadata"); - IndexDocumentOptions indexDocumentOptions4 = - new IndexDocumentOptions.Builder().document(document).metadata(metadata).dryRun(true).build(); - String indexDocumentAndMetadataDryRun = service.indexDocument(indexDocumentOptions4).execute(); - System.out.println(indexDocumentAndMetadataDryRun); - - printHeaderForExample("Dry run for indexing document with provided media type and metadata"); - IndexDocumentOptions indexDocumentOptions5 = new IndexDocumentOptions.Builder().document(document) - .metadata(metadata).mediaType(HttpMediaType.TEXT_HTML).dryRun(true).build(); - String indexDocumentWithMediaTypeAndMetadataDryRun = service.indexDocument(indexDocumentOptions5).execute(); - System.out.println(indexDocumentWithMediaTypeAndMetadataDryRun); - - printHeaderForExample( - "Dry run for indexing document with provided media type, metadata, and convert document config"); - IndexDocumentOptions indexDocumentOptions6 = - new IndexDocumentOptions.Builder().document(document).metadata(metadata).mediaType(HttpMediaType.TEXT_HTML) - .convertDocumentConfig(convertDocumentConfig).dryRun(true).build(); - String indexDocumentWithMediaTypeAndMetadataAndConfigDryRun = - service.indexDocument(indexDocumentOptions6).execute(); - System.out.println(indexDocumentWithMediaTypeAndMetadataAndConfigDryRun); - - printHeaderForExample("Index metadata"); - IndexDocumentOptions indexDocumentOptions7 = new IndexDocumentOptions.Builder().metadata(metadata) - .indexConfiguration(indexConfiguration).dryRun(false).build(); - String indexMetadata = service.indexDocument(indexDocumentOptions7).execute(); - System.out.println(indexMetadata); - - printHeaderForExample("Index a document and metadata"); - IndexDocumentOptions indexDocumentOptions8 = new IndexDocumentOptions.Builder().document(document) - .metadata(metadata).indexConfiguration(indexConfiguration).dryRun(false).build(); - String indexDocumentAndMetadata = service.indexDocument(indexDocumentOptions8).execute(); - System.out.println(indexDocumentAndMetadata); - - printHeaderForExample("Index document with provided media type and metadata"); - IndexDocumentOptions indexDocumentOptions9 = new IndexDocumentOptions.Builder().document(document) - .metadata(metadata).mediaType(HttpMediaType.TEXT_HTML).indexConfiguration(indexConfiguration).build(); - String indexDocumentWithMediaTypeAndMetadata = service.indexDocument(indexDocumentOptions9).execute(); - System.out.println(indexDocumentWithMediaTypeAndMetadata); - - printHeaderForExample("Index document with provided media type, metadata, and convert document config"); - IndexDocumentOptions indexDocumentOptions10 = - new IndexDocumentOptions.Builder().document(document).metadata(metadata).mediaType(HttpMediaType.TEXT_HTML) - .convertDocumentConfig(convertDocumentConfig).indexConfiguration(indexConfiguration).dryRun(false).build(); - String indexDocumentWithMediaTypeAndMetadataAndConfig = service.indexDocument(indexDocumentOptions10).execute(); - System.out.println(indexDocumentWithMediaTypeAndMetadataAndConfig); - - printHeaderForExample("Index document with provided media type, metadata, convert document config, and fields"); - IndexDocumentOptions indexDocumentOptions11 = new IndexDocumentOptions.Builder().document(document) - .metadata(metadata).mediaType(HttpMediaType.TEXT_HTML).convertDocumentConfig(convertDocumentConfig) - .indexConfiguration(indexConfigurationWithFields).dryRun(false).build(); - String indexDocumentWithMediaTypeAndMetadataConfigAndFields = - service.indexDocument(indexDocumentOptions11).execute(); - System.out.println(indexDocumentWithMediaTypeAndMetadataConfigAndFields); - } - - private static void printHeaderForExample(String message) { - System.out.println("\n================================================================================\n" + message - + "\n================================================================================\n"); - } -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/personality_insights/v2/PersonalityInsightsExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/personality_insights/v2/PersonalityInsightsExample.java deleted file mode 100644 index fcc30a29c28..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/personality_insights/v2/PersonalityInsightsExample.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.personality_insights.v2; - -import com.ibm.watson.developer_cloud.personality_insights.v2.model.Profile; - -public class PersonalityInsightsExample { - - public static void main(String[] args) { - PersonalityInsights service = new PersonalityInsights(); - service.setUsernameAndPassword("", ""); - - String text = "Call me Ishmael. Some years ago-never mind how long " - + "precisely-having little or no money in my purse, and nothing " - + "particular to interest me on shore, I thought I would sail about " - + "a little and see the watery part of the world. It is a way " - + "I have of driving off the spleen and regulating the circulation. " - + "Whenever I find myself growing grim about the mouth; whenever it " - + "is a damp, drizzly November in my soul; whenever I find myself " - + "involuntarily pausing before coffin warehouses, and bringing up " - + "the rear of every funeral I meet; and especially whenever my " - + "hypos get such an upper hand of me, that it requires a strong " - + "moral principle to prevent me from deliberately stepping into " - + "the street, and methodically knocking people's hats off-then, " - + "I account it high time to get to sea as soon as I can."; - - Profile profile = service.getProfile(text).execute(); - System.out.println(profile); - } -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/CreateARankerExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/CreateARankerExample.java deleted file mode 100644 index 9ac0fc3d2a1..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/CreateARankerExample.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.retrieve_and_rank.v1; - -import java.io.File; - -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.Ranker; -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.Ranker.Status; -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.Ranking; - -/** - * Example of how to create a {@link Ranking} with {@link RetrieveAndRank}. - */ -public class CreateARankerExample { - - public static void main(String[] args) throws InterruptedException { - // 1 create the service - RetrieveAndRank service = new RetrieveAndRank(); - service.setUsernameAndPassword("", ""); - - // 2 create a ranker - Ranker ranker = service.createRanker("example-ranker-1", new File("")).execute(); - System.out.println("ranker: " + ranker); - - // 3 wait until is trained - while (ranker.getStatus() == Status.TRAINING) { - Thread.sleep(4000); // sleep 4 seconds - ranker = service.getRankerStatus(ranker.getId()).execute(); - System.out.println("ranker status: " + ranker.getStatus()); - } - - // 4 rank answers - Ranking ranking = service.rank(ranker.getId(), new File(""), 5).execute(); - System.out.println("ranking: " + ranking); - - // 5 delete ranker - service.deleteRanker(ranker.getId()); - - } -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/CreateASolrClusterExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/CreateASolrClusterExample.java deleted file mode 100644 index 59a96a88775..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/CreateASolrClusterExample.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.retrieve_and_rank.v1; - -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.SolrCluster; -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.SolrCluster.Status; -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.SolrClusterOptions; - -/** - * Example of how to create a {@link SolrCluster} with {@link RetrieveAndRank}. - */ -public class CreateASolrClusterExample { - public static void main(String[] args) throws InterruptedException { - - // 1 create the service - RetrieveAndRank service = new RetrieveAndRank(); - service.setUsernameAndPassword("", ""); - - // 2 create the Solr Cluster - SolrClusterOptions options = new SolrClusterOptions("", 1); - SolrCluster cluster = service.createSolrCluster(options).execute(); - System.out.println("SolrCluster: " + cluster); - - // 2 wait until the Solr Cluster is available - while (cluster.getStatus() == Status.NOT_AVAILABLE) { - Thread.sleep(10000); // sleep 10 seconds - cluster = service.getSolrCluster(cluster.getId()).execute(); - System.out.println("SolrCluster status: " + cluster.getStatus()); - } - - // 3 list Solr Clusters - System.out.println("Solr clusters: " + service.getSolrClusters().execute()); - - } -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/ResizeASolrClusterExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/ResizeASolrClusterExample.java deleted file mode 100644 index 6c135c67275..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/ResizeASolrClusterExample.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.retrieve_and_rank.v1; - -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.SolrCluster; -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.SolrCluster.Status; -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.SolrClusterOptions; -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.SolrClusterSizeResponse; - -/** - * Example of how to create and resize a {@link SolrCluster} with {@link RetrieveAndRank}. - */ -public class ResizeASolrClusterExample { - public static void main(String[] args) throws InterruptedException { - - // 1 create the service - final RetrieveAndRank service = new RetrieveAndRank(); - service.setUsernameAndPassword("", ""); - // 2 create the Solr Cluster of size 1 - final SolrClusterOptions options = new SolrClusterOptions("", 1); - SolrCluster cluster = service.createSolrCluster(options).execute(); - System.out.println("SolrCluster: " + cluster); - final String solrClusterId = cluster.getId(); - // 2 wait until the Solr Cluster is available - while (cluster.getStatus() == Status.NOT_AVAILABLE) { - Thread.sleep(10000); // sleep 10 seconds - cluster = service.getSolrCluster(solrClusterId).execute(); - System.out.println("SolrCluster status: " + cluster.getStatus()); - } - // 3 resize the cluster form size 1 to size 2 - final int desiredClusterSize = 2; - SolrClusterSizeResponse response = service.resizeSolrCluster(solrClusterId, desiredClusterSize).execute(); - System.out.println(response.toString()); - - // 4 wait until the resize processs is complete - while (response.getCurrentSize() != desiredClusterSize) { - if (response.getStatus() == SolrClusterSizeResponse.Status.ERROR) { - System.out.println(response.getMessage()); - return; - } - System.out.println("Resize status: " + response.getStatus()); - Thread.sleep(10000); - response = service.getSolrClusterResizeStatus(solrClusterId).execute(); - } - System.out.println(response.getMessage()); - System.out.println("resize completed"); - } -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/UploadSolrConfigurationExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/UploadSolrConfigurationExample.java deleted file mode 100644 index 9fe88bb3461..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/retrieve_and_rank/v1/UploadSolrConfigurationExample.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.retrieve_and_rank.v1; - -import java.io.File; -import java.util.List; - -import com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.SolrCluster; - -/** - * Creates a SolrClusterConfiguration using the {@link RetrieveAndRank} service. - *

- * You must first create a Solr cluster and specify its ID here. A Solr cluster can be created with the - * {@link CreateASolrClusterExample}. - */ -public class UploadSolrConfigurationExample { - - public static void main(String[] args) { - // 1 create the service - RetrieveAndRank service = new RetrieveAndRank(); - service.setUsernameAndPassword("", ""); - - // 2 return the existing SolrCluster using the id - SolrCluster cluster = service.getSolrCluster("").execute(); - System.out.println("SolrCluster: " + cluster); - - // 3 upload the Solr configuration directory - File directory = new File("src/test/resources/retrieve_and_rank"); - service.uploadSolrClusterConfigurationDirectory(cluster.getId(), "", directory); - - // 4 list the existing solr configurations - List configs = service.getSolrClusterConfigurations(cluster.getId()).execute().getSolrConfigs(); - System.out.println("Solr configurations: " + configs); - } -} diff --git a/examples/src/main/java/com/ibm/watson/developer_cloud/tradeoff_analytics/v1/TradeoffAnalyticsExample.java b/examples/src/main/java/com/ibm/watson/developer_cloud/tradeoff_analytics/v1/TradeoffAnalyticsExample.java deleted file mode 100644 index 05c6ad7529b..00000000000 --- a/examples/src/main/java/com/ibm/watson/developer_cloud/tradeoff_analytics/v1/TradeoffAnalyticsExample.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright 2017 IBM Corp. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package com.ibm.watson.developer_cloud.tradeoff_analytics.v1; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.Dilemma; -import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.Option; -import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.Problem; -import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.Column; -import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.Column.Goal; -import com.ibm.watson.developer_cloud.tradeoff_analytics.v1.model.column.NumericColumn; - -public class TradeoffAnalyticsExample { - - public static void main(String[] args) { - TradeoffAnalytics service = new TradeoffAnalytics(); - service.setUsernameAndPassword("", ""); - - Problem problem = new Problem("phone"); - - String price = "price"; - String ram = "ram"; - String screen = "screen"; - - // Define the objectives - List columns = new ArrayList(); - problem.setColumns(columns); - - columns.add(new NumericColumn().range(0, 100).key(price).goal(Goal.MIN).objective(true)); - columns.add(new NumericColumn().key(screen).goal(Goal.MAX).objective(true)); - columns.add(new NumericColumn().key(ram).goal(Goal.MAX)); - - // Define the options to choose - List