Skip to content
Merged

2.7.1 #186

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c464f18
fix typo in IDHelper (accoundId --> accountId)
g-may Jan 27, 2016
291157b
Merge pull request #170 from g-may/patch-4
germanattanasio Jan 27, 2016
d237d92
Update README.md
germanattanasio Feb 2, 2016
0dc3bbc
Updated websocket dependency
germanattanasio Feb 9, 2016
1893993
Get the http string from the http InputStream
germanattanasio Feb 9, 2016
6e84e5a
Fixed #171 wrong query parameter
germanattanasio Feb 9, 2016
05b1f69
[concept-insights] Add expires_on and ttl_hours fields to the corpus
germanattanasio Feb 9, 2016
9417177
Added X-Watson-Learning-Opt-Out to prevent payload from being use to
germanattanasio Feb 9, 2016
43e5e51
[language-translation] Allow more than one file to be used when
germanattanasio Feb 9, 2016
140bfa4
Fix for java.naming.InitialContext that was preventing android users
germanattanasio Feb 9, 2016
f43770c
Updated authorizations keys in travis
germanattanasio Feb 9, 2016
a75fab5
[dialog] Deprecate the old method in favor of #177
germanattanasio Feb 9, 2016
e5fce41
Close the input stream for JSON HTTP responses after we read the json.
germanattanasio Feb 9, 2016
bbb6e9a
[language-translation] Sleep for 3 seconds after creating a model to be
germanattanasio Feb 9, 2016
137131d
Fix default headers replacing existing headers in WatsonService
germanattanasio Feb 9, 2016
cc27cb9
Create REReturnType.java
tanmayb123 Feb 9, 2016
46c1441
#184 make sure it runs in java 1.6
germanattanasio Feb 9, 2016
d74517e
[speech-to-text] Fix for WebSocket being disconnected during final
germanattanasio Feb 9, 2016
eca25cc
Update REReturnType.java
tanmayb123 Feb 9, 2016
1e45a23
Update REReturnType.java
tanmayb123 Feb 9, 2016
73b1e0c
Update RelationshipExtraction.java
tanmayb123 Feb 9, 2016
abd876a
Update RelationshipExtraction.java
tanmayb123 Feb 9, 2016
c2cb059
Update REReturnType.java
tanmayb123 Feb 9, 2016
850d4c5
Update RelationshipExtraction.java
tanmayb123 Feb 9, 2016
88b27b4
Rename REReturnType.java to ReturnType.java
tanmayb123 Feb 9, 2016
81e80b5
Update RelationshipExtraction.java
tanmayb123 Feb 9, 2016
cbb5fd5
Update RelationshipExtraction.java
tanmayb123 Feb 9, 2016
c321fd3
Merge pull request #185 from tanmayb123/dev
germanattanasio Feb 9, 2016
5902df2
[speech-to-text] Send close message to the WebSocket once we get the
germanattanasio Feb 9, 2016
4d06966
Merge branch 'dev' of github.com:watson-developer-cloud/java-sdk into…
germanattanasio Feb 9, 2016
322cbd7
[maven-release-plugin] prepare release java-sdk-2.7.1
germanattanasio Feb 9, 2016
e2b4041
[maven-release-plugin] prepare for next development iteration
germanattanasio Feb 9, 2016
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
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ cache:
directories:
- $HOME/.m2/repository
before_install:
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_a973fe4f8e79_key -iv $encrypted_a973fe4f8e79_iv -in config.properties.enc -out src/test/resources/config.properties -d || true'
- pip install --user codecov
- openssl aes-256-cbc -K $encrypted_a973fe4f8e79_key -iv $encrypted_a973fe4f8e79_iv
-in config.properties.enc -out src/test/resources/config.properties -d
notifications:
email: false
env:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ System.out.println(recognizedImage);
```

## Android
he library supports Android 2.3 and above. For Java, the minimum requirement is 1.7.
The library supports Android 2.3 and above. For Java, the minimum requirement is 1.7.
It depends on [OkHttp][] and [gson][].


Expand Down
Binary file modified config.properties.enc
Binary file not shown.
32 changes: 26 additions & 6 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.7.1-SNAPSHOT</version>
<version>2.7.2-SNAPSHOT</version>
<packaging>jar</packaging>
<artifactId>java-sdk</artifactId>
<name>Watson Developer Cloud Java SDK</name>
Expand Down Expand Up @@ -41,7 +41,7 @@
<dependency>
<groupId>com.neovisionaries</groupId>
<artifactId>nv-websocket-client</artifactId>
<version>1.19</version>
<version>1.21</version>
</dependency>
<!-- mockserver -->
<dependency>
Expand Down Expand Up @@ -179,10 +179,10 @@
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<excludes>
<exclude>com/ibm/watson/developer_cloud/*/v*/model/**/*.class</exclude>
<exclude>com/ibm/watson/developer_cloud/**/*Example.*</exclude>
</excludes>
<excludes>
<exclude>com/ibm/watson/developer_cloud/*/v*/model/**/*.class</exclude>
<exclude>com/ibm/watson/developer_cloud/**/*Example.*</exclude>
</excludes>
</configuration>
<executions>
<execution>
Expand All @@ -199,6 +199,26 @@
</execution>
</executions>
</plugin>
<!-- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.11</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java16</artifactId>
<version>1.1</version>
</signature>
</configuration>
</plugin> -->
</plugins>
<resources>
<resource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,56 @@ public class Corpus extends GenericModel {
/** The corpus name. */
private String name;

@SerializedName("ttl_hours")
private Integer ttlInHours;
// ttl_hours (integer, optional): Specify the TTL for the corpus in hours. This will internally
// set the expiration time after which the corpus will be automatically deleted. ,
// expires_on (string, optional): Date and time in standard ISO format at which the corpus will
// expire and be marked for deletion.

@SerializedName("expires_on")
private String expiresOn;

/**
* Gets the time to live in hours.
*
* @return the time to live in hours
*/
public Integer getTtlInHours() {
return ttlInHours;
}

/**
* Sets the time to live in hours. This will internally set the expiration time after which the
* corpus will be automatically deleted.
*
* @param ttlInHours the new time to live in hours
*/
public void setTtlInHours(Integer ttlInHours) {
this.ttlInHours = ttlInHours;
}

/**
* Gets the expires on.
*
* @return the expires on
*/
public String getExpiresOn() {
return expiresOn;
}

/**
* Sets the expires on. The value needs to be in standard ISO format at which the corpus will
* expire and be marked for deletion.
*
* For example: YYYY-MM-DD (e.g. 2016-07-16)
*
* @param expiresOn the new expires on
*/
public void setExpiresOn(String expiresOn) {
this.expiresOn = expiresOn;
}

/**
* Instantiates a new corpus.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ public static String getConceptId(final Concept concept) {
* generated it.
*
* @param corpus Corpus the corpus object,
* @param accoundId String the account id.
* @param accountId String the account id.
* @return the corpus id
*/
public static String getCorpusId(final Corpus corpus, final String accoundId) {
public static String getCorpusId(final Corpus corpus, final String accountId) {
Validate.notNull(corpus, "corpus cannot be null");
if (corpus.getId() != null) {
validate(CORPUS_ID_REGEX, corpus.getId(), "Provide a valid corpus.id (format is " + '"'
+ "/corpora/{account_id}/{corpus} +" + '"' + ")");
return corpus.getId();
} else {
Validate.notNull(corpus.getName(), "corpus.name cannot be null");
return "/corpora/" + accoundId + "/" + corpus.getName();
return "/corpora/" + accountId + "/" + corpus.getName();
}
}

Expand All @@ -107,18 +107,18 @@ public static String getDocumentId(final Document document) {
* generated it.
*
* @param graph Graph the graph object,
* @param accoundId String the account id.
* @param accountId String the account id.
* @return the graph id
*/
public static String getGraphId(final Graph graph, final String accoundId) {
public static String getGraphId(final Graph graph, final String accountId) {
Validate.notNull(graph, "graph object cannot be null");
if (graph.getId() != null) {
validate(GRAPH_ID_REGEX, graph.getId(), "Provide a valid graph.id (format is " + '"'
+ " (/graphs/{account_id}/{graph}) +" + '"' + ")");
return graph.getId();
} else {
Validate.notNull(graph.getName(), "graph.name cannot be null");
return "/graphs/" + accoundId + "/" + graph.getName();
return "/graphs/" + accountId + "/" + graph.getName();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public Conversation converse(final Conversation conversation, String newMessage)
*
* @param params the params
* @return the {@link Conversation} with the response
* @deprecated Use {@link DialogService#converse(Conversation, String)}
*/
public Conversation converse(final Map<String, Object> params) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,8 @@ public interface HttpHeaders {

/** The Authorization token header. */
public static final String X_WATSON_AUTHORIZATION_TOKEN = "X-Watson-Authorization-Token";

/** Allow Watson to collect the payload. */
public static final String X_WATSON_LEARNING_OPT_OUT = "X-Watson-Learning-Opt-Out";

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
* identifies the language in which text is written.
*
* @version v2
* @see <a
* href="http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/language-translation.html">
* @see <a href=
* "http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/language-translation.html">
* Language Translation</a>
*/
public class LanguageTranslation extends WatsonService {
Expand Down Expand Up @@ -68,8 +68,8 @@ public class LanguageTranslation extends WatsonService {
/** The Constant NAME (value is "name"). */
private static final String NAME = "name";

/** The Constant PARALLEL_CORPUS (value is "prallel_corpus"). */
private static final String PARALLEL_CORPUS = "prallel_corpus";
/** The Constant PARALLEL_CORPUS (value is "parallel_corpus"). */
private static final String PARALLEL_CORPUS = "parallel_corpus";

/** The Constant SOURCE (value is "source"). */
private static final String SOURCE = "source";
Expand Down Expand Up @@ -112,10 +112,10 @@ public TranslationModel createModel(CreateModelOptions options) {
if (options.getForcedGlossary() != null)
bodyBuilder.addFormDataPart(FORCED_GLOSSARY, options.getForcedGlossary().getName(),
RequestBody.create(HttpMediaType.BINARY_FILE, options.getForcedGlossary()));
else if (options.getMonolingualCorpus() != null)
if (options.getMonolingualCorpus() != null)
bodyBuilder.addFormDataPart(MONOLINGUAL_CORPUS, options.getMonolingualCorpus().getName(),
RequestBody.create(HttpMediaType.BINARY_FILE, options.getMonolingualCorpus()));
else if (options.getParallelCorpus() != null)
if (options.getParallelCorpus() != null)
bodyBuilder.addFormDataPart(PARALLEL_CORPUS, options.getParallelCorpus().getName(),
RequestBody.create(HttpMediaType.BINARY_FILE, options.getParallelCorpus()));

Expand Down Expand Up @@ -208,9 +208,9 @@ public List<TranslationModel> getModels(final Boolean showDefault, final String
*/
@SuppressWarnings("unchecked")
public List<IdentifiedLanguage> identify(final String text) {
final Request request =
RequestBuilder.post(PATH_IDENTIFY).withBodyContent(text, HttpMediaType.TEXT_PLAIN)
.withHeader(HttpHeaders.ACCEPT, HttpMediaType.APPLICATION_JSON).build();
final Request request = RequestBuilder.post(PATH_IDENTIFY)
.withHeader(HttpHeaders.ACCEPT, HttpMediaType.APPLICATION_JSON)
.withBodyContent(text, HttpMediaType.TEXT_PLAIN).build();

final LanguageList languages = executeRequest(request, LanguageList.class);

Expand Down Expand Up @@ -276,8 +276,9 @@ private TranslationResult translateRequest(String text, String modelId, String s
paragraphs.add(new JsonPrimitive(text));
contentJson.add(TEXT, paragraphs);

final RequestBuilder requestBuilder = RequestBuilder.post(PATH_TRANSLATE);

final RequestBuilder requestBuilder = RequestBuilder.post(PATH_TRANSLATE)
.withHeader(HttpHeaders.ACCEPT, HttpMediaType.APPLICATION_JSON);

if (source != null && !source.isEmpty())
contentJson.addProperty(SOURCE, source);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class RelationshipExtraction extends WatsonService {

/** The dataset. */
private Dataset dataset;

/** The return type. */
private String returnType = "xml";

/**
* Instantiates a new relationship extraction service.
Expand Down Expand Up @@ -65,15 +68,15 @@ public RelationshipExtraction() {
*
* @param text the text to analyze
*
* @return the result as XML string
* @return the result as an XML/JSON string
*/
public String extract(final String text) {
Validate.notNull(dataset, "dataset cannot be null");
Validate.notNull(text, "text cannot be null");

final Request request =
RequestBuilder.post("/v1/sire/0")
.withForm("sid", dataset.getId(), "rt", "xml", "txt", text).build();
.withForm("sid", dataset.getId(), "rt", returnType, "txt", text).build();
final Response response = execute(request);
return ResponseUtil.getString(response);
}
Expand All @@ -96,5 +99,18 @@ public Dataset getDataset() {
public void setDataset(final Dataset dataset) {
this.dataset = dataset;
}

/**
* Sets the returnType.
*
* @param returnType the new returnType
*/
public void setReturnType(final ReturnType returnType) {
if (returnType == ReturnType.XML) {
this.returnType = "xml";
} else if (returnType == ReturnType.JSON) {
this.returnType = "json";
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ibm.watson.developer_cloud.relationship_extraction.v1;

public enum ReturnType {
XML,
JSON
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ protected Response execute(Request request) {

// Set default headers
if (defaultHeaders != null) {
builder.headers(defaultHeaders);
for(String key: defaultHeaders.names())
builder.header(key, defaultHeaders.get(key));
}

// Set User-Agent
Expand Down Expand Up @@ -248,7 +249,7 @@ public String getToken() {
* @return the error message from the JSON object
*/
private String getErrorMessage(Response response) {
String error = ResponseUtil.getResponseString(response);
String error = ResponseUtil.getString(response);
try {

final JsonObject jsonObject = ResponseUtil.getJsonObject(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class WebSocketSpeechToTextClient {
*/
public class WebSocketListener extends WebSocketAdapter {
private RecognizeDelegate delegate;

private boolean audioSent = false;
/**
* Instantiates a new WebSocket listener.
*
Expand All @@ -51,6 +51,7 @@ public class WebSocketListener extends WebSocketAdapter {
public WebSocketListener(RecognizeDelegate delegate) {
super();
this.delegate = delegate;
audioSent = false;
}

/*
Expand All @@ -69,10 +70,8 @@ public void onTextMessage(WebSocket websocket, String message) {
} else if (json.has(RESULTS)) {
SpeechResults transcript = GsonSingleton.getGson().fromJson(message, SpeechResults.class);
delegate.onMessage(transcript);

// if final is true
if (transcript.isFinal())
websocket.disconnect();
} else if (audioSent) {
websocket.sendClose();
}
} catch (JsonParseException e) {
new RuntimeException("Error parsing the incoming message: " + message);
Expand Down Expand Up @@ -174,7 +173,10 @@ public void recognize(InputStream stream, RecognizeOptions options, RecognizeDel

// 4. Send the input stream as binary data
sendInputStream(ws, stream);


// 5. Tell the listener that we sent the audio
listener.audioSent = true;

// 5. Send stop message
ws.sendText(buildStopMessage());

Expand Down Expand Up @@ -221,9 +223,8 @@ private void sendInputStream(WebSocket ws, InputStream stream) throws IOExceptio
else
ws.sendBinary(Arrays.copyOfRange(buffer, 0, read));

Thread.sleep(10);
Thread.sleep(20);
}

stream.close();
}

Expand Down
Loading