Skip to content
Merged

2.6.0 #160

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ APIs and SDKs that use cognitive computing to solve complex problems.
<dependency>
<groupId>com.ibm.watson.developer_cloud</groupId>
<artifactId>java-sdk</artifactId>
<version>2.5.0</version>
<version>2.6.0</version>
</dependency>
```
##### Gradle

```gradle
'com.ibm.watson.developer_cloud:java-sdk:2.5.0'
'com.ibm.watson.developer_cloud:java-sdk:2.6.0'
```

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).
Expand Down Expand Up @@ -481,7 +481,7 @@ Gradle:

```sh
$ cd java-sdk
$ gradle jar # build jar file (build/libs/watson-developer-cloud-2.5.0.jar)
$ gradle jar # build jar file (build/libs/watson-developer-cloud-2.6.0.jar)
$ gradle test # run tests
```

Expand Down Expand Up @@ -551,4 +551,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
[apache_maven]: http://maven.apache.org/
[releases]: https://github.com/watson-developer-cloud/java-sdk/releases

[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-2.5.0/java-sdk-2.5.0-jar-with-dependencies.jar
[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-2.6.0/java-sdk-2.6.0-jar-with-dependencies.jar
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sourceCompatibility = 1.6
targetCompatibility = 1.6
group = 'com.ibm.watson.developercloud'
archivesBaseName = 'watson-developer-cloud'
version = '2.5.0'
version = '2.6.0'

description = 'Client library to use the IBM Watson Services and AlchemyAPI'

Expand Down
Binary file modified config.properties.enc
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public static void main(String[] args) {
service.setUsernameAndPassword("<username>", "<password>");

String[] seeds = new String[] {"nyc", "dc", "london", "big cities"};
String label = "demo";

Job job = service.createJob(label, seeds);
Job job = service.createJob(seeds);

while (service.getJobStatus(job) == Job.Status.AWAITING_WORK
|| service.getJobStatus(job) == Job.Status.IN_FLIGHT) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,84 +1,87 @@
/**
* Copyright 2015 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.http.HttpMediaType;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class DocumentConversionCustomConfigExample {
public static void main(String[] args) {
final String versionDate = "2015-12-14";
DocumentConversion service = new DocumentConversion(versionDate);
service.setUsernameAndPassword("<username>", "<password>");

final File html = new File("src/test/resources/document_conversion/html-with-extra-content-input.htm");
public static void main(String[] args) {
final String versionDate = "2015-12-14";
DocumentConversion service = new DocumentConversion(versionDate);
service.setUsernameAndPassword("<username>", "<password>");

// 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);
System.out.println(htmlToAnswersWithDefaultConfig);
final File html =
new File("src/test/resources/document_conversion/html-with-extra-content-input.htm");

System.out.println("==================================================");
// 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);
System.out.println(htmlToAnswersWithDefaultConfig);

// 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("==================================================");

System.out.println("Convert html document to Answer Units using custom configuration");
final Answers htmlToAnswersWithCustomConfig =
service.convertDocumentToAnswer(html, HttpMediaType.TEXT_HTML, customConfig);
System.out.println(htmlToAnswersWithCustomConfig);
// 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("==================================================");
System.out.println("Convert html document to Answer Units using custom configuration");
final Answers htmlToAnswersWithCustomConfig =
service.convertDocumentToAnswer(html, HttpMediaType.TEXT_HTML, customConfig);
System.out.println(htmlToAnswersWithCustomConfig);

// 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 = service.loadCustomConfig(new FileInputStream(customConfigFilePath));
} catch(FileNotFoundException e ) {
e.printStackTrace();
}
System.out.println("==================================================");

if(customConfigFilePath == null) {
System.err.println("ERROR - Unable to load custom config from file " + customConfigFilePath);
return;
}
// 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 = service.loadCustomConfig(new FileInputStream(customConfigFilePath));
} catch (FileNotFoundException e) {
e.printStackTrace();
}

final Answers htmlToAnswersWithCustomConfigFromFile =
service.convertDocumentToAnswer(html, HttpMediaType.TEXT_HTML, customConfigFromFile);
System.out.println(htmlToAnswersWithCustomConfigFromFile);
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);
System.out.println(htmlToAnswersWithCustomConfigFromFile);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.ibm.watson.developer_cloud.speech_to_text.v1;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import com.ibm.watson.developer_cloud.http.HttpMediaType;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechResults;
import com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.BaseRecognizeDelegate;

/**
* Recognize using WebSockets a sample wav file and print the transcript into the console output.
*/
public class RecognizeUsingWebSockets {
private static CountDownLatch lock = new CountDownLatch(1);

public static void main(String[] args) throws FileNotFoundException, InterruptedException {
SpeechToText service = new SpeechToText();
service.setUsernameAndPassword("<username>", "<password>");

FileInputStream audio = new FileInputStream("src/test/resources/speech_to_text/sample1.wav");

RecognizeOptions options = new RecognizeOptions();
options.continuous(true).interimResults(true).contentType(HttpMediaType.AUDIO_WAV);

service.recognizeUsingWebSockets(audio, options, new BaseRecognizeDelegate() {
@Override
public void onMessage(SpeechResults speechResults) {
System.out.println(speechResults);
if (speechResults.isFinal())
lock.countDown();
}
});

lock.await(20000, TimeUnit.MILLISECONDS);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright 2015 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
Expand All @@ -15,7 +15,6 @@

import java.io.File;

import com.ibm.watson.developer_cloud.http.HttpMediaType;
import com.ibm.watson.developer_cloud.speech_to_text.v1.model.SpeechResults;


Expand All @@ -30,7 +29,7 @@ public static void main(String[] args) {
service.setUsernameAndPassword("<username>", "<password>");

File audio = new File("src/test/resources/speech_to_text/sample1.wav");
SpeechResults transcript = service.recognize(audio, HttpMediaType.AUDIO_WAV);
SpeechResults transcript = service.recognize(audio);

System.out.println(transcript);
}
Expand Down
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ibm.watson.developer_cloud</groupId>
<version>2.5.1-SNAPSHOT</version>
<version>2.6.1-SNAPSHOT</version>
<packaging>jar</packaging>
<artifactId>java-sdk</artifactId>
<name>Watson Developer Cloud Java SDK</name>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.0</version>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand All @@ -35,9 +35,14 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.neovisionaries</groupId>
<artifactId>nv-websocket-client</artifactId>
<version>1.19</version>
</dependency>
<!-- mockserver -->
<dependency>
<groupId>org.mock-server</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ public ConceptExpansion() {
setDataset(Dataset.MT_SAMPLES);
}

/**
* Creates a {@link Job}.
*
* @param seeds List of terms to be used as seeds
*
* @return the {@link Job}
*/
public Job createJob(final String[] seeds) {
return createJob(null, seeds);
}

/**
* Creates a {@link Job}.
*
Expand All @@ -76,7 +87,6 @@ public ConceptExpansion() {
* @return the {@link Job}
*/
public Job createJob(final String label, final String[] seeds) {
Validate.notEmpty(label, "label cannot be null or empty");
Validate.notEmpty(seeds, "seeds cannot be null or empty");
Validate.notNull(dataset, "dataset cannot be null");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,6 @@ public interface HttpHeaders {
*/
public static final String WWW_AUTHENTICATE = "WWW-Authenticate";

/** The Authorization token header. */
public static final String X_WATSON_AUTHORIZATION_TOKEN = "X-Watson-Authorization-Token";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright 2015 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.service;

import com.ibm.watson.developer_cloud.http.HttpStatus;
import com.squareup.okhttp.Response;

/**
* 409 Conflict (HTTP/1.1 - RFC 2616)
*/
public class ConflictException extends ServiceResponseException {

/**
* The Constant serialVersionUID.
*/
private static final long serialVersionUID = 1L;

/**
* Instantiates a new Forbidden Exception.
*
* @param message the error message
* @param response the HTTP response
*/
public ConflictException(String message, Response response) {
super(HttpStatus.CONFLICT, message, response);
}

}
Loading