Skip to content

Commit fc9865a

Browse files
committed
feat(Natural Language Understanding): Add generated code from newest version of service
1 parent f464e8c commit fc9865a

25 files changed

+589
-111
lines changed

natural-language-understanding/src/main/java/com/ibm/watson/natural_language_understanding/v1/NaturalLanguageUnderstanding.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,22 @@
2020
import com.ibm.cloud.sdk.core.util.GsonSingleton;
2121
import com.ibm.cloud.sdk.core.util.ResponseConverterUtils;
2222
import com.ibm.cloud.sdk.core.util.Validator;
23+
import com.ibm.watson.common.SdkCommon;
2324
import com.ibm.watson.natural_language_understanding.v1.model.AnalysisResults;
2425
import com.ibm.watson.natural_language_understanding.v1.model.AnalyzeOptions;
2526
import com.ibm.watson.natural_language_understanding.v1.model.DeleteModelOptions;
2627
import com.ibm.watson.natural_language_understanding.v1.model.ListModelsOptions;
2728
import com.ibm.watson.natural_language_understanding.v1.model.ListModelsResults;
29+
import java.util.Map;
30+
import java.util.Map.Entry;
2831

2932
/**
3033
* Analyze various features of text content at scale. Provide text, raw HTML, or a public URL and IBM Watson Natural
3134
* Language Understanding will give you results for the features you request. The service cleans HTML content before
3235
* analysis by default, so the results can ignore most advertisements and other unwanted content.
3336
*
3437
* You can create [custom models](https://cloud.ibm.com/docs/services/natural-language-understanding/customizing.html)
35-
* with Watson Knowledge Studio to detect custom entities and relations in Natural Language Understanding.
38+
* with Watson Knowledge Studio to detect custom entities, relations, and categories in Natural Language Understanding.
3639
*
3740
* @version v1
3841
* @see <a href="http://www.ibm.com/watson/developercloud/natural-language-understanding.html">Natural Language
@@ -103,7 +106,8 @@ public NaturalLanguageUnderstanding(String versionDate, IamOptions iamOptions) {
103106
* - Metadata
104107
* - Relations
105108
* - Semantic roles
106-
* - Sentiment.
109+
* - Sentiment
110+
* - Syntax (Experimental).
107111
*
108112
* @param analyzeOptions the {@link AnalyzeOptions} containing the options for the call
109113
* @return a {@link ServiceCall} with a response type of {@link AnalysisResults}
@@ -113,9 +117,13 @@ public ServiceCall<AnalysisResults> analyze(AnalyzeOptions analyzeOptions) {
113117
String[] pathSegments = { "v1/analyze" };
114118
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
115119
builder.query("version", versionDate);
116-
builder.header("X-IBMCloud-SDK-Analytics",
117-
"service_name=natural-language-understanding;service_version=v1;operation_id=analyze");
120+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("natural-language-understanding", "v1", "analyze");
121+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
122+
builder.header(header.getKey(), header.getValue());
123+
}
124+
builder.header("Accept", "application/json");
118125
final JsonObject contentJson = new JsonObject();
126+
contentJson.add("features", GsonSingleton.getGson().toJsonTree(analyzeOptions.features()));
119127
if (analyzeOptions.text() != null) {
120128
contentJson.addProperty("text", analyzeOptions.text());
121129
}
@@ -125,7 +133,6 @@ public ServiceCall<AnalysisResults> analyze(AnalyzeOptions analyzeOptions) {
125133
if (analyzeOptions.url() != null) {
126134
contentJson.addProperty("url", analyzeOptions.url());
127135
}
128-
contentJson.add("features", GsonSingleton.getGson().toJsonTree(analyzeOptions.features()));
129136
if (analyzeOptions.clean() != null) {
130137
contentJson.addProperty("clean", analyzeOptions.clean());
131138
}
@@ -163,8 +170,11 @@ public ServiceCall<Void> deleteModel(DeleteModelOptions deleteModelOptions) {
163170
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
164171
pathParameters));
165172
builder.query("version", versionDate);
166-
builder.header("X-IBMCloud-SDK-Analytics",
167-
"service_name=natural-language-understanding;service_version=v1;operation_id=deleteModel");
173+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("natural-language-understanding", "v1", "deleteModel");
174+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
175+
builder.header(header.getKey(), header.getValue());
176+
}
177+
builder.header("Accept", "application/json");
168178
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
169179
}
170180

@@ -182,8 +192,11 @@ public ServiceCall<ListModelsResults> listModels(ListModelsOptions listModelsOpt
182192
String[] pathSegments = { "v1/models" };
183193
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
184194
builder.query("version", versionDate);
185-
builder.header("X-IBMCloud-SDK-Analytics",
186-
"service_name=natural-language-understanding;service_version=v1;operation_id=listModels");
195+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("natural-language-understanding", "v1", "listModels");
196+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
197+
builder.header(header.getKey(), header.getValue());
198+
}
199+
builder.header("Accept", "application/json");
187200
if (listModelsOptions != null) {
188201
}
189202
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ListModelsResults.class));

natural-language-understanding/src/main/java/com/ibm/watson/natural_language_understanding/v1/model/AnalysisResults.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.ibm.cloud.sdk.core.service.model.GenericModel;
1919

2020
/**
21-
* Results of the analysis, organized by feature.
21+
* Analysis results for each requested feature.
2222
*/
2323
public class AnalysisResults extends GenericModel {
2424

@@ -27,17 +27,18 @@ public class AnalysisResults extends GenericModel {
2727
private String analyzedText;
2828
@SerializedName("retrieved_url")
2929
private String retrievedUrl;
30-
private Usage usage;
30+
private AnalysisResultsUsage usage;
3131
private List<ConceptsResult> concepts;
3232
private List<EntitiesResult> entities;
3333
private List<KeywordsResult> keywords;
3434
private List<CategoriesResult> categories;
3535
private EmotionResult emotion;
36-
private MetadataResult metadata;
36+
private AnalysisResultsMetadata metadata;
3737
private List<RelationsResult> relations;
3838
@SerializedName("semantic_roles")
3939
private List<SemanticRolesResult> semanticRoles;
4040
private SentimentResult sentiment;
41+
private SyntaxResult syntax;
4142

4243
/**
4344
* Gets the language.
@@ -75,11 +76,11 @@ public String getRetrievedUrl() {
7576
/**
7677
* Gets the usage.
7778
*
78-
* Usage information.
79+
* API usage information for the request.
7980
*
8081
* @return the usage
8182
*/
82-
public Usage getUsage() {
83+
public AnalysisResultsUsage getUsage() {
8384
return usage;
8485
}
8586

@@ -130,8 +131,7 @@ public List<CategoriesResult> getCategories() {
130131
/**
131132
* Gets the emotion.
132133
*
133-
* The detected anger, disgust, fear, joy, or sadness that is conveyed by the content. Emotion information can be
134-
* returned for detected entities, keywords, or user-specified target phrases found in the text.
134+
* The anger, disgust, fear, joy, or sadness conveyed by the content.
135135
*
136136
* @return the emotion
137137
*/
@@ -142,12 +142,11 @@ public EmotionResult getEmotion() {
142142
/**
143143
* Gets the metadata.
144144
*
145-
* The authors, publication date, title, prominent page image, and RSS/ATOM feeds of the webpage. Supports URL and
146-
* HTML input types.
145+
* Webpage metadata, such as the author and the title of the page.
147146
*
148147
* @return the metadata
149148
*/
150-
public MetadataResult getMetadata() {
149+
public AnalysisResultsMetadata getMetadata() {
151150
return metadata;
152151
}
153152

@@ -183,4 +182,15 @@ public List<SemanticRolesResult> getSemanticRoles() {
183182
public SentimentResult getSentiment() {
184183
return sentiment;
185184
}
185+
186+
/**
187+
* Gets the syntax.
188+
*
189+
* Tokens and sentences returned from syntax analysis.
190+
*
191+
* @return the syntax
192+
*/
193+
public SyntaxResult getSyntax() {
194+
return syntax;
195+
}
186196
}

natural-language-understanding/src/main/java/com/ibm/watson/natural_language_understanding/v1/model/MetadataResult.java renamed to natural-language-understanding/src/main/java/com/ibm/watson/natural_language_understanding/v1/model/AnalysisResultsMetadata.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
import com.ibm.cloud.sdk.core.service.model.GenericModel;
1919

2020
/**
21-
* The authors, publication date, title, prominent page image, and RSS/ATOM feeds of the webpage. Supports URL and HTML
22-
* input types.
21+
* Webpage metadata, such as the author and the title of the page.
2322
*/
24-
public class MetadataResult extends GenericModel {
23+
public class AnalysisResultsMetadata extends GenericModel {
2524

2625
private List<Author> authors;
2726
@SerializedName("publication_date")

natural-language-understanding/src/main/java/com/ibm/watson/natural_language_understanding/v1/model/Usage.java renamed to natural-language-understanding/src/main/java/com/ibm/watson/natural_language_understanding/v1/model/AnalysisResultsUsage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import com.ibm.cloud.sdk.core.service.model.GenericModel;
1717

1818
/**
19-
* Usage information.
19+
* API usage information for the request.
2020
*/
21-
public class Usage extends GenericModel {
21+
public class AnalysisResultsUsage extends GenericModel {
2222

2323
private Long features;
2424
@SerializedName("text_characters")

natural-language-understanding/src/main/java/com/ibm/watson/natural_language_understanding/v1/model/AnalyzeOptions.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
*/
2121
public class AnalyzeOptions extends GenericModel {
2222

23+
private Features features;
2324
private String text;
2425
private String html;
2526
private String url;
26-
private Features features;
2727
private Boolean clean;
2828
private String xpath;
2929
private Boolean fallbackToRaw;
@@ -35,10 +35,10 @@ public class AnalyzeOptions extends GenericModel {
3535
* Builder.
3636
*/
3737
public static class Builder {
38+
private Features features;
3839
private String text;
3940
private String html;
4041
private String url;
41-
private Features features;
4242
private Boolean clean;
4343
private String xpath;
4444
private Boolean fallbackToRaw;
@@ -47,16 +47,16 @@ public static class Builder {
4747
private Long limitTextCharacters;
4848

4949
private Builder(AnalyzeOptions analyzeOptions) {
50-
text = analyzeOptions.text;
51-
html = analyzeOptions.html;
52-
url = analyzeOptions.url;
53-
features = analyzeOptions.features;
54-
clean = analyzeOptions.clean;
55-
xpath = analyzeOptions.xpath;
56-
fallbackToRaw = analyzeOptions.fallbackToRaw;
57-
returnAnalyzedText = analyzeOptions.returnAnalyzedText;
58-
language = analyzeOptions.language;
59-
limitTextCharacters = analyzeOptions.limitTextCharacters;
50+
this.features = analyzeOptions.features;
51+
this.text = analyzeOptions.text;
52+
this.html = analyzeOptions.html;
53+
this.url = analyzeOptions.url;
54+
this.clean = analyzeOptions.clean;
55+
this.xpath = analyzeOptions.xpath;
56+
this.fallbackToRaw = analyzeOptions.fallbackToRaw;
57+
this.returnAnalyzedText = analyzeOptions.returnAnalyzedText;
58+
this.language = analyzeOptions.language;
59+
this.limitTextCharacters = analyzeOptions.limitTextCharacters;
6060
}
6161

6262
/**
@@ -83,6 +83,17 @@ public AnalyzeOptions build() {
8383
return new AnalyzeOptions(this);
8484
}
8585

86+
/**
87+
* Set the features.
88+
*
89+
* @param features the features
90+
* @return the AnalyzeOptions builder
91+
*/
92+
public Builder features(Features features) {
93+
this.features = features;
94+
return this;
95+
}
96+
8697
/**
8798
* Set the text.
8899
*
@@ -116,17 +127,6 @@ public Builder url(String url) {
116127
return this;
117128
}
118129

119-
/**
120-
* Set the features.
121-
*
122-
* @param features the features
123-
* @return the AnalyzeOptions builder
124-
*/
125-
public Builder features(Features features) {
126-
this.features = features;
127-
return this;
128-
}
129-
130130
/**
131131
* Set the clean.
132132
*
@@ -196,10 +196,10 @@ public Builder limitTextCharacters(long limitTextCharacters) {
196196

197197
private AnalyzeOptions(Builder builder) {
198198
Validator.notNull(builder.features, "features cannot be null");
199+
features = builder.features;
199200
text = builder.text;
200201
html = builder.html;
201202
url = builder.url;
202-
features = builder.features;
203203
clean = builder.clean;
204204
xpath = builder.xpath;
205205
fallbackToRaw = builder.fallbackToRaw;
@@ -217,6 +217,17 @@ public Builder newBuilder() {
217217
return new Builder(this);
218218
}
219219

220+
/**
221+
* Gets the features.
222+
*
223+
* Specific features to analyze the document for.
224+
*
225+
* @return the features
226+
*/
227+
public Features features() {
228+
return features;
229+
}
230+
220231
/**
221232
* Gets the text.
222233
*
@@ -250,17 +261,6 @@ public String url() {
250261
return url;
251262
}
252263

253-
/**
254-
* Gets the features.
255-
*
256-
* Analysis features and options.
257-
*
258-
* @return the features
259-
*/
260-
public Features features() {
261-
return features;
262-
}
263-
264264
/**
265265
* Gets the clean.
266266
*

0 commit comments

Comments
 (0)