use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognition method getClassifier.
/**
* Retrieve classifier details.
*
* Retrieve information about a custom classifier.
*
* @param getClassifierOptions the {@link GetClassifierOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Classifier}
*/
public ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierOptions) {
Validator.notNull(getClassifierOptions, "getClassifierOptions cannot be null");
String[] pathSegments = { "v3/classifiers" };
String[] pathParameters = { getClassifierOptions.classifierId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class));
}
use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testCreateClassifier.
/**
* Test create a classifier.
*
* @throws FileNotFoundException the file not found exception
* @throws InterruptedException the interrupted exception
*/
@Ignore
@Test
public void testCreateClassifier() throws FileNotFoundException, InterruptedException {
String classifierName = "integration-test-java-sdk";
String carClassifier = "car";
String baseballClassifier = "baseball";
File carImages = new File("src/test/resources/visual_recognition/car_positive.zip");
File baseballImages = new File("src/test/resources/visual_recognition/baseball_positive.zip");
InputStream negativeImages = new FileInputStream("src/test/resources/visual_recognition/negative.zip");
CreateClassifierOptions.Builder builder = new CreateClassifierOptions.Builder().name(classifierName);
builder.addClass(carClassifier, carImages);
builder.addClass(baseballClassifier, baseballImages);
builder.negativeExamples(negativeImages);
builder.negativeExamplesFilename("negative.zip");
Classifier newClass = service.createClassifier(builder.build()).execute();
try {
assertEquals(classifierName, newClass.getName());
boolean ready = false;
for (int x = 0; (x < 20) && !ready; x++) {
Thread.sleep(2000);
GetClassifierOptions getOptions = new GetClassifierOptions.Builder(newClass.getClassifierId()).build();
newClass = service.getClassifier(getOptions).execute();
ready = newClass.getStatus().equals(Status.READY);
}
assertEquals(Status.READY, newClass.getStatus());
} finally {
DeleteClassifierOptions deleteOptions = new DeleteClassifierOptions.Builder(newClass.getClassifierId()).build();
service.deleteClassifier(deleteOptions).execute();
}
}
use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testCreateClassifierAndClassifyImage.
/**
* Test create a classifier.
*
* @throws FileNotFoundException the file not found exception
* @throws InterruptedException the interrupted exception
*/
@Ignore
@Test
public void testCreateClassifierAndClassifyImage() throws FileNotFoundException, InterruptedException {
String classifierName = "integration-test-java-sdk";
String carClassifier = "car";
String baseballClassifier = "baseball";
File carImages = new File("src/test/resources/visual_recognition/car_positive.zip");
File baseballImages = new File("src/test/resources/visual_recognition/baseball_positive.zip");
File negativeImages = new File("src/test/resources/visual_recognition/negative.zip");
File imageToClassify = new File("src/test/resources/visual_recognition/car.png");
CreateClassifierOptions.Builder builder = new CreateClassifierOptions.Builder().name(classifierName);
builder.addClass(carClassifier, carImages);
builder.addClass(baseballClassifier, baseballImages);
builder.negativeExamples(negativeImages);
Classifier newClassifier = service.createClassifier(builder.build()).execute();
try {
assertEquals(classifierName, newClassifier.getName());
boolean ready = false;
for (int x = 0; (x < 20) && !ready; x++) {
Thread.sleep(2000);
GetClassifierOptions getOptions = new GetClassifierOptions.Builder(newClassifier.getClassifierId()).build();
newClassifier = service.getClassifier(getOptions).execute();
ready = newClassifier.getStatus().equals(Status.READY);
}
assertEquals(Status.READY, newClassifier.getStatus());
ClassifyOptions options = new ClassifyOptions.Builder().imagesFile(imageToClassify).build();
ClassifiedImages classification = service.classify(options).execute();
assertNotNull(classification);
} finally {
DeleteClassifierOptions deleteOptions = new DeleteClassifierOptions.Builder(newClassifier.getClassifierId()).build();
service.deleteClassifier(deleteOptions).execute();
}
}
use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions 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());
}
use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions in project java-sdk by watson-developer-cloud.
the class NaturalLanguageClassifierTest method testGetClassifier.
/**
* Test get classifier.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testGetClassifier() throws InterruptedException {
server.enqueue(jsonResponse(classifier));
GetClassifierOptions getOptions = new GetClassifierOptions.Builder().classifierId(classifierId).build();
final Classifier response = service.getClassifier(getOptions).execute();
final RecordedRequest request = server.takeRequest();
assertEquals(CLASSIFIERS_PATH + "/" + classifierId, request.getPath());
assertEquals(classifier, response);
}
Aggregations