Skip to content

Commit c207261

Browse files
committed
chore(Natural Language Classifier): Apply manual changes
1 parent dd53464 commit c207261

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
import okhttp3.MultipartBody;
3535
import okhttp3.RequestBody;
3636

37+
import java.io.ByteArrayInputStream;
38+
import java.io.File;
39+
import java.io.FileNotFoundException;
40+
import java.util.HashMap;
41+
import java.util.Map;
42+
3743
/**
3844
* IBM Watson™ Natural Language Classifier uses machine learning algorithms to return the top matching predefined
3945
* classes for short text input. You create and train a classifier to connect predefined classes to example texts so
@@ -211,4 +217,90 @@ public ServiceCall<ClassifierList> listClassifiers() {
211217
return listClassifiers(null);
212218
}
213219

220+
/**
221+
* Classify.
222+
*
223+
* This method is here for backwards-compatibility with the other version of classify.
224+
*
225+
* @param classifierId the classifier ID
226+
* @param text the submitted phrase to classify
227+
* @return the classification of a phrase with a given classifier
228+
*/
229+
public ServiceCall<Classification> classify(String classifierId, String text) {
230+
ClassifyOptions classifyOptions = new ClassifyOptions.Builder()
231+
.classifierId(classifierId)
232+
.text(text)
233+
.build();
234+
return classify(classifyOptions);
235+
}
236+
237+
/**
238+
* Create classifier.
239+
*
240+
* This method is here for backwards-compatibility with the old version of createClassifier.
241+
*
242+
* @param name the classifier name
243+
* @param language IETF primary language for the classifier. for example: 'en'
244+
* @param trainingData the set of questions and their "keys" used to adapt a system to a domain (the ground truth)
245+
* @return the classifier
246+
* @throws FileNotFoundException if the file could not be found
247+
*/
248+
public ServiceCall<Classifier> createClassifier(String name, String language, File trainingData)
249+
throws FileNotFoundException {
250+
Map<String, String> metadataMap = new HashMap<>();
251+
metadataMap.put("name", name);
252+
metadataMap.put("language", language);
253+
String metadataString = GsonSingleton.getGson().toJson(metadataMap);
254+
255+
CreateClassifierOptions createClassifierOptions = new CreateClassifierOptions.Builder()
256+
.metadata(new ByteArrayInputStream(metadataString.getBytes()))
257+
.trainingData(trainingData)
258+
.build();
259+
260+
return createClassifier(createClassifierOptions);
261+
}
262+
263+
/**
264+
* Delete classifier.
265+
*
266+
* This method is here for backwards-compatibility with the old version of deleteClassifier.
267+
*
268+
* @param classifierId the classifier ID
269+
* @return the service call
270+
*/
271+
public ServiceCall<Void> deleteClassifier(String classifierId) {
272+
DeleteClassifierOptions deleteClassifierOptions = new DeleteClassifierOptions.Builder()
273+
.classifierId(classifierId)
274+
.build();
275+
276+
return deleteClassifier(deleteClassifierOptions);
277+
}
278+
279+
/**
280+
* Get information about a classifier.
281+
*
282+
* This method is here for backwards-compatibility with the old version of getClassifier.
283+
*
284+
* @param classifierId the classifier ID
285+
* @return the classifier
286+
*/
287+
public ServiceCall<Classifier> getClassifier(String classifierId) {
288+
GetClassifierOptions getClassifierOptions = new GetClassifierOptions.Builder()
289+
.classifierId(classifierId)
290+
.build();
291+
292+
return getClassifier(getClassifierOptions);
293+
}
294+
295+
/**
296+
* List classifiers.
297+
*
298+
* This method is here for backwards-compatibility with the old version of getClassifiers, which has been renamed
299+
* to listClassifiers.
300+
*
301+
* @return the classifier list
302+
*/
303+
public ServiceCall<ClassifierList> getClassifiers() {
304+
return listClassifiers();
305+
}
214306
}

0 commit comments

Comments
 (0)