use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier in project java-sdk by watson-developer-cloud.
the class VisualRecognitionExample method main.
public static void main(String[] args) {
VisualRecognition service = new VisualRecognition("2016-05-20");
service.setApiKey("<api-key>");
System.out.println("Classify an image");
ClassifyOptions options = new ClassifyOptions.Builder().imagesFile(new File("src/test/resources/visual_recognition/car.png")).imagesFilename("car.png").build();
ClassifiedImages result = service.classify(options).execute();
System.out.println(result);
System.out.println("Create a classifier with positive and negative images");
CreateClassifierOptions createOptions = new CreateClassifierOptions.Builder().name("foo").addClass("car", new File("src/test/resources/visual_recognition/car_positive.zip")).addClass("baseball", new File("src/test/resources/visual_recognition/baseball_positive.zip")).negativeExamples(new File("src/test/resources/visual_recognition/negative.zip")).build();
Classifier foo = service.createClassifier(createOptions).execute();
System.out.println(foo);
System.out.println("Classify using the 'Car' classifier");
options = new ClassifyOptions.Builder().imagesFile(new File("src/test/resources/visual_recognition/car.png")).imagesFilename("car.png").addClassifierId(foo.getClassifierId()).build();
result = service.classify(options).execute();
System.out.println(result);
System.out.println("Update a classifier with more positive images");
UpdateClassifierOptions updateOptions = new UpdateClassifierOptions.Builder().classifierId(foo.getClassifierId()).addClass("car", new File("src/test/resources/visual_recognition/car_positive.zip")).build();
Classifier updatedFoo = service.updateClassifier(updateOptions).execute();
System.out.println(updatedFoo);
}
use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifier method classify.
/**
* Classify a phrase.
*
* Returns label information for the input. The status must be `Available` before you can use the classifier to
* classify text.
*
* @param classifyOptions the {@link ClassifyOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Classification}
*/
public ServiceCall<Classification> classify(ClassifyOptions classifyOptions) {
Validator.notNull(classifyOptions, "classifyOptions cannot be null");
String[] pathSegments = { "v1/classifiers", "classify" };
String[] pathParameters = { classifyOptions.classifierId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("text", classifyOptions.text());
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classification.class));
}
use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifier method classifyCollection.
/**
* 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));
}
use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifierIT method eDelete.
/**
* Test delete classifier. Do not delete the pre created classifier. We need it for classify
*/
@Test
public void eDelete() {
List<Classifier> classifiers = service.listClassifiers().execute().getClassifiers();
for (Classifier classifier : classifiers) {
if (!classifier.getClassifierId().equals(preCreatedClassifierId)) {
DeleteClassifierOptions deleteOptions = new DeleteClassifierOptions.Builder().classifierId(classifier.getClassifierId()).build();
service.deleteClassifier(deleteOptions).execute();
}
}
}
use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifierIT method bGetClassifier.
/**
* Test get classifier.
*/
@Test
public void bGetClassifier() {
final Classifier classifier;
try {
GetClassifierOptions getOptions = new GetClassifierOptions.Builder().classifierId(classifierId).build();
classifier = service.getClassifier(getOptions).execute();
} catch (NotFoundException e) {
// The build should not fail here, because this is out of our control.
throw new AssumptionViolatedException(e.getMessage(), e);
}
assertNotNull(classifier);
assertEquals(classifierId, classifier.getClassifierId());
assertEquals(Classifier.Status.TRAINING, classifier.getStatus());
}
Aggregations