@@ -8,6 +8,7 @@ APIs and SDKs that use cognitive computing to solve complex problems. |
8 | 8 |
|
9 | 9 |
|
10 | 10 | ## Table of Contents |
| 11 | + * [Breaking Changes for v3.0](#breaking-changes-for-v30) |
11 | 12 | * [Installation](#installation) |
12 | 13 | * [Maven](#maven) |
13 | 14 | * [Gradle](#gradle) |
@@ -38,24 +39,62 @@ APIs and SDKs that use cognitive computing to solve complex problems. |
38 | 39 | * [License](#license) |
39 | 40 | * [Contributing](#contributing) |
40 | 41 |
|
41 | | -## Installation |
| 42 | +## Breaking Changes for v3.0 |
| 43 | + |
| 44 | +The version 3.0.0-RC1 is a major release focused on simplicity and consistency. Several breaking changes were introduced. |
| 45 | + |
| 46 | +### Synchronous vs Asynchronous |
| 47 | + |
| 48 | +Before 3.0 all the API calls were synchonous |
| 49 | +```java |
| 50 | +List<Dialog> dialogs = dialogService.getDialogs(); |
| 51 | +System.out.println(dialogs); |
| 52 | +``` |
| 53 | +Now to do synchonous call you need to add `execute()` |
| 54 | + |
| 55 | +```java |
| 56 | +List<Dialog> dialogs = dialogService.getDialogs().execute(); |
| 57 | +System.out.println(dialogs); |
| 58 | +``` |
| 59 | +To do asynchronous calls you need to specify a callback |
| 60 | + |
| 61 | +```java |
| 62 | +List<Dialog> dialogs = dialogService.getDialogs().enqueue(new Callback<List<Dialog>() { |
| 63 | + @Override |
| 64 | + public void onFailure(Exception e) { |
| 65 | + |
| 66 | + } |
42 | 67 |
|
43 | | -[][jar] |
| 68 | + @Override |
| 69 | + public void onResponse(List<Dialog> response) throws IOException { |
| 70 | + System.out.println(response); |
| 71 | + } |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +* Websocke requests are now using `okhttp-ws` instead of `nv-websocket-client` |
| 76 | +* Several deprecated services have been removed |
| 77 | + |
| 78 | +## Installation |
44 | 79 |
|
45 | 80 | ##### Maven |
46 | 81 | ```xml |
47 | 82 | <dependency> |
48 | 83 | <groupId>com.ibm.watson.developer_cloud</groupId> |
49 | 84 | <artifactId>java-sdk</artifactId> |
50 | | - <version>3.0.0</version> |
| 85 | + <version>3.0.0-RC1</version> |
51 | 86 | </dependency> |
52 | 87 | ``` |
53 | 88 | ##### Gradle |
54 | 89 |
|
55 | 90 | ```gradle |
56 | | -'com.ibm.watson.developer_cloud:java-sdk:3.0.0' |
| 91 | +'com.ibm.watson.developer_cloud:java-sdk:3.0.0-RC1' |
57 | 92 | ``` |
58 | 93 |
|
| 94 | +##### JAR |
| 95 | + |
| 96 | +Download the jar file [here][jar]. |
| 97 | + |
59 | 98 | Now, you are ready to see some [examples](https://github.com/watson-developer-cloud/java-sdk/tree/master/examples/java/com/ibm/watson/developer_cloud). |
60 | 99 |
|
61 | 100 | ## Usage |
@@ -106,7 +145,7 @@ service.setApiKey("<api_key>"); |
106 | 145 |
|
107 | 146 | Map<String,Object> params = new HashMap<String, Object>(); |
108 | 147 | params.put(AlchemyLanguage.TEXT, "IBM Watson won the Jeopardy television show hosted by Alex Trebek"); |
109 | | -DocumentSentiment sentiment = service.getSentiment(params); |
| 148 | +DocumentSentiment sentiment = service.getSentiment(params).execute(); |
110 | 149 |
|
111 | 150 | System.out.println(sentiment); |
112 | 151 | ``` |
@@ -123,7 +162,7 @@ service.setApiKey("<api_key>"); |
123 | 162 | File image = new File("src/test/resources/alchemy/obama.jpg"); |
124 | 163 | Boolean forceShowAll = false; |
125 | 164 | Boolean knowledgeGraph = false; |
126 | | -ImageKeywords keywords = service.getImageKeywords(image, forceShowAll, knowledgeGraph); |
| 165 | +ImageKeywords keywords = service.getImageKeywords(image, forceShowAll, knowledgeGraph).execute(); |
127 | 166 |
|
128 | 167 | System.out.println(keywords); |
129 | 168 | ``` |
@@ -148,7 +187,7 @@ params.put(AlchemyDataNews.START, "1440720000"); |
148 | 187 | params.put(AlchemyDataNews.END, "1441407600"); |
149 | 188 | params.put(AlchemyDataNews.COUNT, 7); |
150 | 189 |
|
151 | | -DocumentsResult result = service.getNewsDocuments(params); |
| 190 | +DocumentsResult result = service.getNewsDocuments(params).execute(); |
152 | 191 |
|
153 | 192 | System.out.println(result); |
154 | 193 | ``` |
@@ -162,7 +201,8 @@ ConceptInsights service = new ConceptInsights(); |
162 | 201 | service.setUsernameAndPassword("<username>", "<password>"); |
163 | 202 |
|
164 | 203 | Annotations annotations = service.annotateText(Graph.WIKIPEDIA, |
165 | | - "IBM Watson won the Jeopardy television show hosted by Alex Trebek"); |
| 204 | + "IBM Watson won the Jeopardy television show hosted by Alex Trebek") |
| 205 | + .execute(); |
166 | 206 |
|
167 | 207 | System.out.println(annotations); |
168 | 208 | ``` |
@@ -174,7 +214,7 @@ Returns the dialog list using the [Dialog][dialog] service. |
174 | 214 | DialogService service = new DialogService(); |
175 | 215 | service.setUsernameAndPassword("<username>", "<password>"); |
176 | 216 |
|
177 | | -List<Dialog> dialogs = service.getDialogs(); |
| 217 | +List<Dialog> dialogs = service.getDialogs().execute(); |
178 | 218 | System.out.println(dialogs); |
179 | 219 | ``` |
180 | 220 |
|
@@ -188,7 +228,7 @@ DocumentConversion service = new DocumentConversion("2015-12-01"); |
188 | 228 | service.setUsernameAndPassword("<username>", "<password>"); |
189 | 229 |
|
190 | 230 | File doc = new File("src/test/resources/document_conversion/word-document-heading-input.doc"); |
191 | | -Answers htmlToAnswers = service.convertDocumentToAnswer(doc); |
| 231 | +Answers htmlToAnswers = service.convertDocumentToAnswer(doc).execute(); |
192 | 232 | System.out.println(htmlToAnswers); |
193 | 233 | ``` |
194 | 234 |
|
@@ -200,7 +240,10 @@ Example: Translate 'hello' from English to Spanish using the [Language Translati |
200 | 240 | LanguageTranslation service = new LanguageTranslation(); |
201 | 241 | service.setUsernameAndPassword("<username>", "<password>"); |
202 | 242 |
|
203 | | -TranslationResult translationResult = service.translate("hello", "en", "es"); |
| 243 | +TranslationResult translationResult = service.translate( |
| 244 | + "hello", Language.ENGLISH, Language.SPANISH) |
| 245 | + .execute(); |
| 246 | + |
204 | 247 | System.out.println(translationResult); |
205 | 248 | ``` |
206 | 249 |
|
@@ -211,7 +254,7 @@ Use [Natural Language Classifier](http://www.ibm.com/smarterplanet/us/en/ibmwats |
211 | 254 | NaturalLanguageClassifier service = new NaturalLanguageClassifier(); |
212 | 255 | service.setUsernameAndPassword("<username>", "<password>"); |
213 | 256 |
|
214 | | -Classification classification = service.classify("<classifier-id>", "Is it sunny?"); |
| 257 | +Classification classification = service.classify("<classifier-id>", "Is it sunny?").execute(); |
215 | 258 | System.out.println(classification); |
216 | 259 | ``` |
217 | 260 |
|
@@ -244,7 +287,7 @@ String text = "Call me Ishmael. Some years ago-never mind how long precisely-hav |
244 | 287 | + "city of the Manhattoes, belted round by wharves as Indian isles by coral reefs-commerce surrounds " |
245 | 288 | + "it with her surf. Right and left, the streets take you waterward."; |
246 | 289 |
|
247 | | -Profile profile = service.getProfile(text); |
| 290 | +Profile profile = service.getProfile(text).execute(); |
248 | 291 | System.out.println(profile); |
249 | 292 | ``` |
250 | 293 |
|
@@ -263,7 +306,7 @@ RelationshipExtraction service = new RelationshipExtraction(); |
263 | 306 | service.setUsernameAndPassword("<username>", "<password>"); |
264 | 307 |
|
265 | 308 | service.setDataset(Dataset.ENGLISH_NEWS); |
266 | | -String response = service.extract("IBM Watson Developer Cloud"); |
| 309 | +String response = service.extract("IBM Watson Developer Cloud").execute(); |
267 | 310 | System.out.println(response); |
268 | 311 | ``` |
269 | 312 |
|
@@ -280,13 +323,13 @@ service.setUsernameAndPassword("<username>", "<password>"); |
280 | 323 |
|
281 | 324 | // 1 create the Solr Cluster |
282 | 325 | SolrClusterOptions options = new SolrClusterOptions("my-cluster-name", 1); |
283 | | -SolrCluster cluster = service.createSolrCluster(options); |
| 326 | +SolrCluster cluster = service.createSolrCluster(options).execute(); |
284 | 327 | System.out.println("Solr cluster: " + cluster); |
285 | 328 |
|
286 | 329 | // 2 wait until the Solr Cluster is available |
287 | 330 | while (cluster.getStatus() == Status.NOT_AVAILABLE) { |
288 | 331 | Thread.sleep(10000); // sleep 10 seconds |
289 | | - cluster = service.getSolrCluster(cluster.getId()); |
| 332 | + cluster = service.getSolrCluster(cluster.getId()).execute(); |
290 | 333 | System.out.println("Solr cluster status: " + cluster.getStatus()); |
291 | 334 | } |
292 | 335 |
|
@@ -306,7 +349,7 @@ service.setUsernameAndPassword("<username>", "<password>"); |
306 | 349 |
|
307 | 350 | File audio = new File("src/test/resources/sample1.wav"); |
308 | 351 |
|
309 | | -SpeechResults transcript = service.recognize(audio, HttpMediaType.AUDIO_WAV); |
| 352 | +SpeechResults transcript = service.recognize(audio, HttpMediaType.AUDIO_WAV).execute(); |
310 | 353 | System.out.println(transcript); |
311 | 354 | ``` |
312 | 355 |
|
@@ -315,7 +358,24 @@ System.out.println(transcript); |
315 | 358 | Speech to Text supports WebSocket, the url is: |
316 | 359 | `wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize` |
317 | 360 |
|
318 | | -We recommend you use [this](http://java-websocket.org/) java client. |
| 361 | + ```java |
| 362 | +SpeechToText service = new SpeechToText(); |
| 363 | +service.setUsernameAndPassword("<username>", "<password>"); |
| 364 | +
|
| 365 | +File audio = new File("src/test/resources/sample1.wav"); |
| 366 | +
|
| 367 | +RecognizeOptions options = new RecognizeOptions(); |
| 368 | + options.continuous(true).interimResults(true).contentType(HttpMediaType.AUDIO_WAV); |
| 369 | +
|
| 370 | + service.recognizeUsingWebSocket(audio, options, new BaseRecognizeCallback() { |
| 371 | + @Override |
| 372 | + public void onTranscription(SpeechResults speechResults) { |
| 373 | + System.out.println(speechResults); |
| 374 | + } |
| 375 | + ); |
| 376 | + // wait 20 seconds for the asynchronous response |
| 377 | + Thread.sleep(20000); |
| 378 | +``` |
319 | 379 |
|
320 | 380 | ### Text to Speech |
321 | 381 | Use the [Text to Speech][text_to_speech] service to get the available voices to synthesize. |
@@ -324,7 +384,7 @@ Use the [Text to Speech][text_to_speech] service to get the available voices to |
324 | 384 | TextToSpeech service = new TextToSpeech(); |
325 | 385 | service.setUsernameAndPassword("<username>", "<password>"); |
326 | 386 |
|
327 | | -List<Voice> voices = service.getVoices(); |
| 387 | +List<Voice> voices = service.getVoices().execute(); |
328 | 388 | System.out.println(voices); |
329 | 389 | ``` |
330 | 390 |
|
@@ -348,7 +408,7 @@ String text = |
348 | 408 | + "business outcomes. Economy has nothing to do with it."; |
349 | 409 |
|
350 | 410 | // Call the service and get the tone |
351 | | -ToneAnalysis tone = service.getTone(text); |
| 411 | +ToneAnalysis tone = service.getTone(text).execute(); |
352 | 412 | System.out.println(tone); |
353 | 413 | ``` |
354 | 414 |
|
@@ -398,7 +458,7 @@ optimusSpecs.put(screen, 5); |
398 | 458 | options.add(new Option("3", "LG Optimus G").withValues(optimusSpecs)); |
399 | 459 |
|
400 | 460 | // Call the service and get the resolution |
401 | | -Dilemma dilemma = service.dilemmas(problem); |
| 461 | +Dilemma dilemma = service.dilemmas(problem).execute(); |
402 | 462 | System.out.println(dilemma); |
403 | 463 | ``` |
404 | 464 |
|
@@ -410,7 +470,7 @@ VisualInsights service = new VisualInsights(); |
410 | 470 | service.setUsernameAndPassword("<username>", "<password>"); |
411 | 471 |
|
412 | 472 | File images = new File("src/test/resources/visual_insights/images.zip"); |
413 | | -Summary summary = service.getSummary(images); |
| 473 | +Summary summary = service.getSummary(images).execute(); |
414 | 474 |
|
415 | 475 | System.out.println(summary); |
416 | 476 | ``` |
@@ -427,7 +487,7 @@ service.setUsernameAndPassword("<username>", "<password>"); |
427 | 487 |
|
428 | 488 | File image = new File("src/test/resources/visual_recognition/car.png"); |
429 | 489 |
|
430 | | -VisualRecognitionImages recognizedImage = service.recognize(image); |
| 490 | +VisualRecognitionImages recognizedImage = service.recognize(image).execute(); |
431 | 491 | System.out.println(recognizedImage); |
432 | 492 | ``` |
433 | 493 |
|
@@ -454,7 +514,7 @@ Gradle: |
454 | 514 |
|
455 | 515 | ```sh |
456 | 516 | $ cd java-sdk |
457 | | - $ gradle jar # build jar file (build/libs/watson-developer-cloud-3.0.0.jar) |
| 517 | + $ gradle jar # build jar file (build/libs/watson-developer-cloud-3.0.0-RC1.jar) |
458 | 518 | $ gradle test # run tests |
459 | 519 | ``` |
460 | 520 |
|
@@ -524,4 +584,4 @@ See [CONTRIBUTING.md](.github/CONTRIBUTING.md). |
524 | 584 | [apache_maven]: http://maven.apache.org/ |
525 | 585 | [releases]: https://github.com/watson-developer-cloud/java-sdk/releases |
526 | 586 |
|
527 | | -[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-3.0.0/java-sdk-3.0.0-jar-with-dependencies.jar |
| 587 | +[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-3.0.0-RC1/java-sdk-3.0.0-RC1-jar-with-dependencies.jar |