Skip to content

Commit 76af58d

Browse files
Merge branch 'master' of github.com:watson-developer-cloud/java-sdk into 2.10.0
2 parents 3b410dc + 2570488 commit 76af58d

File tree

11 files changed

+117
-23
lines changed

11 files changed

+117
-23
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ gradlew.bat
1212
target
1313
bin/
1414
*.iml
15+
*.ipr
16+
*.iws
1517
src/test/resources/config.properties

.utility/push-javadoc-to-gh-pages.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ if [ "$TRAVIS_REPO_SLUG" == "watson-developer-cloud/java-sdk" ] && [ "$TRAVIS_PU
1313

1414
cp -rf ../target/site/apidocs/* docs/$TRAVIS_BRANCH
1515
../.utility/generate_index_html.sh > index.html
16+
17+
# update the latest/ symlink
18+
# on tagged builds, $TRAVIS_TAG is set to the tag, but it's blank on regular builds, unlike $TRAVIS_BRANCH
19+
if [ $TRAVIS_TAG ]; then
20+
rm latest
21+
ln -s ./$TRAVIS_TAG latest
22+
fi
1623

1724
git add -f .
1825
git commit -m "Latest javadoc for $TRAVIS_BRANCH ($TRAVIS_COMMIT)"

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -363,20 +363,21 @@ Use the [Tone Analyzer][tone_analyzer] service to get the tone of your email.
363363
ToneAnalyzer service = new ToneAnalyzer(ToneAnalyzer.VERSION_DATE_2016_02_11);
364364
service.setUsernameAndPassword("<username>", "<password>");
365365

366-
367-
String text = "I know the times are difficult! Our sales have been "
368-
+ "disappointing for the past three quarters for our data analytics "
369-
+ "product suite. We have a competitive data analytics product "
370-
+ "suite in the industry. But we need to do our job selling it! "
371-
+ "We need to acknowledge and fix our sales challenges.";
366+
String text =
367+
"I know the times are difficult! Our sales have been "
368+
+ "disappointing for the past three quarters for our data analytics "
369+
+ "product suite. We have a competitive data analytics product "
370+
+ "suite in the industry. But we need to do our job selling it! "
371+
+ "We need to acknowledge and fix our sales challenges. "
372+
+ "We can’t blame the economy for our lack of execution! "
373+
+ "We are missing critical sales opportunities. "
374+
+ "Our product is in no way inferior to the competitor products. "
375+
+ "Our clients are hungry for analytical tools to improve their "
376+
+ "business outcomes. Economy has nothing to do with it.";
372377

373378
// Call the service and get the tone
374-
Tone tone = service.getTone(text, Scorecard.EMAIL);
375-
System.out.println(tone);
376-
377-
378379
ToneAnalysis tone = service.getTone(text);
379-
System.out.println(tone);
380+
System.out.println(tone);
380381
```
381382

382383

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: 'java'
22
apply plugin: 'maven'
33
apply plugin: 'eclipse'
4+
apply plugin: 'idea'
45

56
sourceCompatibility = 1.6
67
targetCompatibility = 1.6

examples/java/com/ibm/watson/developer_cloud/alchemy_data_news/v1/GetNewsDocumentExample.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
/**
2727
* Getting 7 documents between Friday 28th August 2015 and Friday 4th September 2015 using the
2828
* {@link AlchemyDataNews} API.
29-
*
29+
*
30+
* Example from java-sdk: https://github.com/watson-developer-cloud/java-sdk
3031
*/
3132
public class GetNewsDocumentExample {
3233

@@ -44,6 +45,10 @@ public static void main(String[] args) {
4445
params.put(AlchemyDataNews.START, "1440720000");
4546
params.put(AlchemyDataNews.END, "1441407600");
4647
params.put(AlchemyDataNews.COUNT, 7);
48+
//Query on adjacent nested fields:
49+
params.put("q.enriched.url.enrichedTitle.entities.entity", "|text=IBM,type=company|");
50+
params.put("q.enriched.url.enrichedTitle.docSentiment.type", "positive");
51+
params.put("q.enriched.url.enrichedTitle.taxonomy.taxonomy_.label", "technology and computing");
4752

4853
DocumentsResult result = service.getNewsDocuments(params);
4954

src/main/java/com/ibm/watson/developer_cloud/alchemy/v1/AlchemyLanguage.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.ibm.watson.developer_cloud.alchemy.v1.model.Feeds;
3333
import com.ibm.watson.developer_cloud.alchemy.v1.model.Keywords;
3434
import com.ibm.watson.developer_cloud.alchemy.v1.model.Language;
35+
import com.ibm.watson.developer_cloud.alchemy.v1.model.LanguageSelection;
3536
import com.ibm.watson.developer_cloud.alchemy.v1.model.Microformats;
3637
import com.ibm.watson.developer_cloud.alchemy.v1.model.SAORelations;
3738
import com.ibm.watson.developer_cloud.alchemy.v1.model.Taxonomies;
@@ -79,6 +80,9 @@ public class AlchemyLanguage extends AlchemyService {
7980
public static final String XPATH = "xpath";
8081
public static final String TARGETS = "targets";
8182
public static final String ANCHOR_DATE = "anchorDate";
83+
84+
// language to be used with request
85+
private LanguageSelection language = LanguageSelection.DETECT;
8286

8387
private static final SimpleDateFormat anchorDateFormat =
8488
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -105,6 +109,10 @@ private <T extends AlchemyGenericModel> T executeRequest(Map<String, Object> par
105109
// Return json
106110
params.put(OUTPUT_MODE, "json");
107111

112+
if (language != LanguageSelection.DETECT) {
113+
params.put("language", language.toString().toLowerCase());
114+
}
115+
108116
// Prevent jsonp to be returned
109117
params.remove(JSONP);
110118

@@ -115,6 +123,17 @@ private <T extends AlchemyGenericModel> T executeRequest(Map<String, Object> par
115123
return executeRequest(requestBuilder.build(), returnType);
116124
}
117125

126+
127+
/**
128+
* Allows users to set language of input text.
129+
*
130+
* @param language The language to use
131+
*/
132+
public void setLanguage(LanguageSelection language) {
133+
this.language = language;
134+
}
135+
136+
118137
/**
119138
* Extracts the authors from a URL or HTML.
120139
*

src/main/java/com/ibm/watson/developer_cloud/alchemy/v1/model/ImageKeyword.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public class ImageKeyword extends GenericModel {
3232
/** The text. */
3333
private String text;
3434

35+
/** The hierarchy. */
36+
private String hierarchy;
37+
3538
/**
3639
* Gets the score.
3740
*
@@ -68,4 +71,22 @@ public void setText(String text) {
6871
this.text = text;
6972
}
7073

74+
/**
75+
* Sets the hierarchy.
76+
*
77+
* @param hierarchy The hierarchy.
78+
*/
79+
public void setHierarchy(String hierarchy) {
80+
this.hierarchy = hierarchy;
81+
}
82+
83+
/**
84+
* Gets the hierarchy. A value is only present if the request that produced this instance
85+
* was made with {@code knowledgeGraph = true}.
86+
*
87+
* @return The hierarchy, if it exists.
88+
*/
89+
public String getHierarchy() {
90+
return hierarchy;
91+
}
7192
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ibm.watson.developer_cloud.alchemy.v1.model;
2+
3+
public enum LanguageSelection {
4+
ENGLISH,
5+
FRENCH,
6+
GERMAN,
7+
ITALIAN,
8+
PORTUGESE,
9+
RUSSIAN,
10+
SPANISH,
11+
SWEDISH,
12+
DETECT
13+
}

src/main/java/com/ibm/watson/developer_cloud/alchemy/v1/util/ImageKeywordTypeAdapter.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
*/
1414
package com.ibm.watson.developer_cloud.alchemy.v1.util;
1515

16-
import java.io.IOException;
17-
1816
import com.google.gson.TypeAdapter;
1917
import com.google.gson.stream.JsonReader;
2018
import com.google.gson.stream.JsonToken;
2119
import com.google.gson.stream.JsonWriter;
2220
import com.ibm.watson.developer_cloud.alchemy.v1.model.ImageKeyword;
2321

22+
import java.io.IOException;
23+
2424
/**
2525
* Type Adapter for the {@link ImageKeyword} class.
2626
*/
@@ -50,6 +50,16 @@ public ImageKeyword read(JsonReader reader) throws IOException {
5050
final String score = reader.nextString();
5151
if (score != null && !score.isEmpty())
5252
ImageKeyword.setScore(Double.valueOf(score));
53+
} else if (name.equals("knowledgeGraph")) {
54+
reader.beginObject();
55+
if (reader.hasNext() && reader.nextName().equals("typeHierarchy")) {
56+
final String hierarchy = reader.nextString();
57+
ImageKeyword.setHierarchy(hierarchy);
58+
}
59+
while (reader.hasNext()) {
60+
reader.skipValue();
61+
}
62+
reader.endObject();
5363
} else {
5464
reader.skipValue();
5565
}

src/main/java/com/ibm/watson/developer_cloud/alchemy/v1/util/TaxonomyTypeAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public void write(JsonWriter writer, Taxonomy value) throws IOException {
7878

7979
if (value.getScore() != null)
8080
writer.name("score").value(value.getScore());
81-
if (value.getConfident() != null)
82-
writer.name("confident").value(value.getConfident());
81+
if (value.getConfident() == false)
82+
writer.name("confident").value("no");
8383
if (value.getLabel() != null)
8484
writer.name("label").value(value.getLabel());
8585

0 commit comments

Comments
 (0)