Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import com.ibm.watson.developer_cloud.http.RequestBuilder;
import com.ibm.watson.developer_cloud.http.ServiceCall;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classification;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassificationCollection;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifierList;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyCollectionOptions;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyOptions;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.CreateClassifierOptions;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.DeleteClassifierOptions;
Expand Down Expand Up @@ -94,6 +96,27 @@ public ServiceCall<Classification> classify(ClassifyOptions classifyOptions) {
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classification.class));
}

/**
* Classify multiple phrases.
*
* Returns label information for multiple phrases. The status must be `Available` before you can use the classifier to
* classify text. Note that classifying Japanese texts is a beta feature.
*
* @param classifyCollectionOptions the {@link ClassifyCollectionOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link ClassificationCollection}
*/
public ServiceCall<ClassificationCollection> classifyCollection(ClassifyCollectionOptions classifyCollectionOptions) {
Validator.notNull(classifyCollectionOptions, "classifyCollectionOptions cannot be null");
String[] pathSegments = { "v1/classifiers", "classify_collection" };
String[] pathParameters = { classifyCollectionOptions.classifierId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
final JsonObject contentJson = new JsonObject();
contentJson.add("collection", GsonSingleton.getGson().toJsonTree(classifyCollectionOptions.collection()));
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ClassificationCollection.class));
}

/**
* Create classifier.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2018 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.ibm.watson.developer_cloud.natural_language_classifier.v1.model;

import java.util.List;

import com.google.gson.annotations.SerializedName;
import com.ibm.watson.developer_cloud.service.model.GenericModel;

/**
* Response from the classifier for multiple phrases.
*/
public class ClassificationCollection extends GenericModel {

@SerializedName("classifier_id")
private String classifierId;
private String url;
private List<CollectionItem> collection;

/**
* Gets the classifierId.
*
* Unique identifier for this classifier.
*
* @return the classifierId
*/
public String getClassifierId() {
return classifierId;
}

/**
* Gets the url.
*
* Link to the classifier.
*
* @return the url
*/
public String getUrl() {
return url;
}

/**
* Gets the collection.
*
* An array of classifier responses for each submitted phrase.
*
* @return the collection
*/
public List<CollectionItem> getCollection() {
return collection;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright 2018 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.ibm.watson.developer_cloud.natural_language_classifier.v1.model;

import java.util.ArrayList;
import java.util.List;

import com.ibm.watson.developer_cloud.service.model.GenericModel;
import com.ibm.watson.developer_cloud.util.Validator;

/**
* The classifyCollection options.
*/
public class ClassifyCollectionOptions extends GenericModel {

private String classifierId;
private List<ClassifyInput> collection;

/**
* Builder.
*/
public static class Builder {
private String classifierId;
private List<ClassifyInput> collection;

private Builder(ClassifyCollectionOptions classifyCollectionOptions) {
classifierId = classifyCollectionOptions.classifierId;
collection = classifyCollectionOptions.collection;
}

/**
* Instantiates a new builder.
*/
public Builder() {
}

/**
* Instantiates a new builder with required properties.
*
* @param classifierId the classifierId
* @param collection the collection
*/
public Builder(String classifierId, List<ClassifyInput> collection) {
this.classifierId = classifierId;
this.collection = collection;
}

/**
* Builds a ClassifyCollectionOptions.
*
* @return the classifyCollectionOptions
*/
public ClassifyCollectionOptions build() {
return new ClassifyCollectionOptions(this);
}

/**
* Adds an classifyInput to collection.
*
* @param classifyInput the new classifyInput
* @return the ClassifyCollectionOptions builder
*/
public Builder addClassifyInput(ClassifyInput classifyInput) {
Validator.notNull(classifyInput, "classifyInput cannot be null");
if (this.collection == null) {
this.collection = new ArrayList<ClassifyInput>();
}
this.collection.add(classifyInput);
return this;
}

/**
* Set the classifierId.
*
* @param classifierId the classifierId
* @return the ClassifyCollectionOptions builder
*/
public Builder classifierId(String classifierId) {
this.classifierId = classifierId;
return this;
}

/**
* Set the collection.
* Existing collection will be replaced.
*
* @param collection the collection
* @return the ClassifyCollectionOptions builder
*/
public Builder collection(List<ClassifyInput> collection) {
this.collection = collection;
return this;
}
}

private ClassifyCollectionOptions(Builder builder) {
Validator.notEmpty(builder.classifierId, "classifierId cannot be empty");
Validator.notNull(builder.collection, "collection cannot be null");
classifierId = builder.classifierId;
collection = builder.collection;
}

/**
* New builder.
*
* @return a ClassifyCollectionOptions builder
*/
public Builder newBuilder() {
return new Builder(this);
}

/**
* Gets the classifierId.
*
* Classifier ID to use.
*
* @return the classifierId
*/
public String classifierId() {
return classifierId;
}

/**
* Gets the collection.
*
* The submitted phrases.
*
* @return the collection
*/
public List<ClassifyInput> collection() {
return collection;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2018 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.ibm.watson.developer_cloud.natural_language_classifier.v1.model;

import com.ibm.watson.developer_cloud.service.model.GenericModel;

/**
* Request payload to classify.
*/
public class ClassifyInput extends GenericModel {

private String text;

/**
* Gets the text.
*
* The submitted phrase.
*
* @return the text
*/
public String getText() {
return text;
}

/**
* Sets the text.
*
* @param text the new text
*/
public void setText(final String text) {
this.text = text;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2018 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.ibm.watson.developer_cloud.natural_language_classifier.v1.model;

import java.util.List;

import com.google.gson.annotations.SerializedName;
import com.ibm.watson.developer_cloud.service.model.GenericModel;

/**
* Response from the classifier for a phrase in a collection.
*/
public class CollectionItem extends GenericModel {

private String text;
@SerializedName("top_class")
private String topClass;
private List<ClassifiedClass> classes;

/**
* Gets the text.
*
* The submitted phrase.
*
* @return the text
*/
public String getText() {
return text;
}

/**
* Gets the topClass.
*
* The class with the highest confidence.
*
* @return the topClass
*/
public String getTopClass() {
return topClass;
}

/**
* Gets the classes.
*
* An array of up to ten class-confidence pairs sorted in descending order of confidence.
*
* @return the classes
*/
public List<ClassifiedClass> getClasses() {
return classes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ public Builder newBuilder() {
* Gets the metadata.
*
* Metadata in JSON format. The metadata identifies the language of the data, and an optional name to identify the
* classifier.
* classifier. Specify the language with the 2-letter primary language code as assigned in ISO standard 639. Supported
* languages are English (`en`), Arabic (`ar`), French (`fr`), German, (`de`), Italian (`it`), Japanese (`ja`), Korean
* (`ko`), Brazilian Portuguese (`pt`), and Spanish (`es`).
*
* @return the metadata
*/
Expand All @@ -189,9 +191,9 @@ public String metadataFilename() {
/**
* Gets the trainingData.
*
* Training data in CSV format. Each text value must have at least one class. The data can include up to 15,000
* records. For details, see [Using your own
* data](https://console.bluemix.net/docs/services/natural-language-classifier/using-your-data.html).
* Training data in CSV format. Each text value must have at least one class. The data can include up to 20,000
* records. For details, see [Data
* preparation](https://console.bluemix.net/docs/services/natural-language-classifier/using-your-data.html).
*
* @return the trainingData
*/
Expand Down
Loading