Skip to content

Commit e86d559

Browse files
committed
Merge branch 'master' of github.com:watson-developer-cloud/java-sdk
2 parents 768007a + 840e684 commit e86d559

4 files changed

Lines changed: 40 additions & 3 deletions

File tree

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
*
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/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)