Skip to content

Commit e455134

Browse files
Merge branch 'develop' into example-updates
2 parents b3473ce + b3713c3 commit e455134

File tree

9 files changed

+434
-4
lines changed

9 files changed

+434
-4
lines changed

natural-language-classifier/src/main/java/com/ibm/watson/developer_cloud/natural_language_classifier/v1/NaturalLanguageClassifier.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
import com.ibm.watson.developer_cloud.http.RequestBuilder;
1717
import com.ibm.watson.developer_cloud.http.ServiceCall;
1818
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classification;
19+
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassificationCollection;
1920
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier;
2021
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifierList;
22+
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyCollectionOptions;
2123
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyOptions;
2224
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.CreateClassifierOptions;
2325
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.DeleteClassifierOptions;
@@ -94,6 +96,27 @@ public ServiceCall<Classification> classify(ClassifyOptions classifyOptions) {
9496
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classification.class));
9597
}
9698

99+
/**
100+
* Classify multiple phrases.
101+
*
102+
* Returns label information for multiple phrases. The status must be `Available` before you can use the classifier to
103+
* classify text. Note that classifying Japanese texts is a beta feature.
104+
*
105+
* @param classifyCollectionOptions the {@link ClassifyCollectionOptions} containing the options for the call
106+
* @return a {@link ServiceCall} with a response type of {@link ClassificationCollection}
107+
*/
108+
public ServiceCall<ClassificationCollection> classifyCollection(ClassifyCollectionOptions classifyCollectionOptions) {
109+
Validator.notNull(classifyCollectionOptions, "classifyCollectionOptions cannot be null");
110+
String[] pathSegments = { "v1/classifiers", "classify_collection" };
111+
String[] pathParameters = { classifyCollectionOptions.classifierId() };
112+
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
113+
pathParameters));
114+
final JsonObject contentJson = new JsonObject();
115+
contentJson.add("collection", GsonSingleton.getGson().toJsonTree(classifyCollectionOptions.collection()));
116+
builder.bodyJson(contentJson);
117+
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ClassificationCollection.class));
118+
}
119+
97120
/**
98121
* Create classifier.
99122
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.developer_cloud.natural_language_classifier.v1.model;
14+
15+
import java.util.List;
16+
17+
import com.google.gson.annotations.SerializedName;
18+
import com.ibm.watson.developer_cloud.service.model.GenericModel;
19+
20+
/**
21+
* Response from the classifier for multiple phrases.
22+
*/
23+
public class ClassificationCollection extends GenericModel {
24+
25+
@SerializedName("classifier_id")
26+
private String classifierId;
27+
private String url;
28+
private List<CollectionItem> collection;
29+
30+
/**
31+
* Gets the classifierId.
32+
*
33+
* Unique identifier for this classifier.
34+
*
35+
* @return the classifierId
36+
*/
37+
public String getClassifierId() {
38+
return classifierId;
39+
}
40+
41+
/**
42+
* Gets the url.
43+
*
44+
* Link to the classifier.
45+
*
46+
* @return the url
47+
*/
48+
public String getUrl() {
49+
return url;
50+
}
51+
52+
/**
53+
* Gets the collection.
54+
*
55+
* An array of classifier responses for each submitted phrase.
56+
*
57+
* @return the collection
58+
*/
59+
public List<CollectionItem> getCollection() {
60+
return collection;
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.developer_cloud.natural_language_classifier.v1.model;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
import com.ibm.watson.developer_cloud.service.model.GenericModel;
19+
import com.ibm.watson.developer_cloud.util.Validator;
20+
21+
/**
22+
* The classifyCollection options.
23+
*/
24+
public class ClassifyCollectionOptions extends GenericModel {
25+
26+
private String classifierId;
27+
private List<ClassifyInput> collection;
28+
29+
/**
30+
* Builder.
31+
*/
32+
public static class Builder {
33+
private String classifierId;
34+
private List<ClassifyInput> collection;
35+
36+
private Builder(ClassifyCollectionOptions classifyCollectionOptions) {
37+
classifierId = classifyCollectionOptions.classifierId;
38+
collection = classifyCollectionOptions.collection;
39+
}
40+
41+
/**
42+
* Instantiates a new builder.
43+
*/
44+
public Builder() {
45+
}
46+
47+
/**
48+
* Instantiates a new builder with required properties.
49+
*
50+
* @param classifierId the classifierId
51+
* @param collection the collection
52+
*/
53+
public Builder(String classifierId, List<ClassifyInput> collection) {
54+
this.classifierId = classifierId;
55+
this.collection = collection;
56+
}
57+
58+
/**
59+
* Builds a ClassifyCollectionOptions.
60+
*
61+
* @return the classifyCollectionOptions
62+
*/
63+
public ClassifyCollectionOptions build() {
64+
return new ClassifyCollectionOptions(this);
65+
}
66+
67+
/**
68+
* Adds an classifyInput to collection.
69+
*
70+
* @param classifyInput the new classifyInput
71+
* @return the ClassifyCollectionOptions builder
72+
*/
73+
public Builder addClassifyInput(ClassifyInput classifyInput) {
74+
Validator.notNull(classifyInput, "classifyInput cannot be null");
75+
if (this.collection == null) {
76+
this.collection = new ArrayList<ClassifyInput>();
77+
}
78+
this.collection.add(classifyInput);
79+
return this;
80+
}
81+
82+
/**
83+
* Set the classifierId.
84+
*
85+
* @param classifierId the classifierId
86+
* @return the ClassifyCollectionOptions builder
87+
*/
88+
public Builder classifierId(String classifierId) {
89+
this.classifierId = classifierId;
90+
return this;
91+
}
92+
93+
/**
94+
* Set the collection.
95+
* Existing collection will be replaced.
96+
*
97+
* @param collection the collection
98+
* @return the ClassifyCollectionOptions builder
99+
*/
100+
public Builder collection(List<ClassifyInput> collection) {
101+
this.collection = collection;
102+
return this;
103+
}
104+
}
105+
106+
private ClassifyCollectionOptions(Builder builder) {
107+
Validator.notEmpty(builder.classifierId, "classifierId cannot be empty");
108+
Validator.notNull(builder.collection, "collection cannot be null");
109+
classifierId = builder.classifierId;
110+
collection = builder.collection;
111+
}
112+
113+
/**
114+
* New builder.
115+
*
116+
* @return a ClassifyCollectionOptions builder
117+
*/
118+
public Builder newBuilder() {
119+
return new Builder(this);
120+
}
121+
122+
/**
123+
* Gets the classifierId.
124+
*
125+
* Classifier ID to use.
126+
*
127+
* @return the classifierId
128+
*/
129+
public String classifierId() {
130+
return classifierId;
131+
}
132+
133+
/**
134+
* Gets the collection.
135+
*
136+
* The submitted phrases.
137+
*
138+
* @return the collection
139+
*/
140+
public List<ClassifyInput> collection() {
141+
return collection;
142+
}
143+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.developer_cloud.natural_language_classifier.v1.model;
14+
15+
import com.ibm.watson.developer_cloud.service.model.GenericModel;
16+
17+
/**
18+
* Request payload to classify.
19+
*/
20+
public class ClassifyInput extends GenericModel {
21+
22+
private String text;
23+
24+
/**
25+
* Gets the text.
26+
*
27+
* The submitted phrase.
28+
*
29+
* @return the text
30+
*/
31+
public String getText() {
32+
return text;
33+
}
34+
35+
/**
36+
* Sets the text.
37+
*
38+
* @param text the new text
39+
*/
40+
public void setText(final String text) {
41+
this.text = text;
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2018 IBM Corp. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.ibm.watson.developer_cloud.natural_language_classifier.v1.model;
14+
15+
import java.util.List;
16+
17+
import com.google.gson.annotations.SerializedName;
18+
import com.ibm.watson.developer_cloud.service.model.GenericModel;
19+
20+
/**
21+
* Response from the classifier for a phrase in a collection.
22+
*/
23+
public class CollectionItem extends GenericModel {
24+
25+
private String text;
26+
@SerializedName("top_class")
27+
private String topClass;
28+
private List<ClassifiedClass> classes;
29+
30+
/**
31+
* Gets the text.
32+
*
33+
* The submitted phrase.
34+
*
35+
* @return the text
36+
*/
37+
public String getText() {
38+
return text;
39+
}
40+
41+
/**
42+
* Gets the topClass.
43+
*
44+
* The class with the highest confidence.
45+
*
46+
* @return the topClass
47+
*/
48+
public String getTopClass() {
49+
return topClass;
50+
}
51+
52+
/**
53+
* Gets the classes.
54+
*
55+
* An array of up to ten class-confidence pairs sorted in descending order of confidence.
56+
*
57+
* @return the classes
58+
*/
59+
public List<ClassifiedClass> getClasses() {
60+
return classes;
61+
}
62+
}

natural-language-classifier/src/main/java/com/ibm/watson/developer_cloud/natural_language_classifier/v1/model/CreateClassifierOptions.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ public Builder newBuilder() {
167167
* Gets the metadata.
168168
*
169169
* Metadata in JSON format. The metadata identifies the language of the data, and an optional name to identify the
170-
* classifier.
170+
* classifier. Specify the language with the 2-letter primary language code as assigned in ISO standard 639. Supported
171+
* languages are English (`en`), Arabic (`ar`), French (`fr`), German, (`de`), Italian (`it`), Japanese (`ja`), Korean
172+
* (`ko`), Brazilian Portuguese (`pt`), and Spanish (`es`).
171173
*
172174
* @return the metadata
173175
*/
@@ -189,9 +191,9 @@ public String metadataFilename() {
189191
/**
190192
* Gets the trainingData.
191193
*
192-
* Training data in CSV format. Each text value must have at least one class. The data can include up to 15,000
193-
* records. For details, see [Using your own
194-
* data](https://console.bluemix.net/docs/services/natural-language-classifier/using-your-data.html).
194+
* Training data in CSV format. Each text value must have at least one class. The data can include up to 20,000
195+
* records. For details, see [Data
196+
* preparation](https://console.bluemix.net/docs/services/natural-language-classifier/using-your-data.html).
195197
*
196198
* @return the trainingData
197199
*/

0 commit comments

Comments
 (0)