Search in sources :

Example 16 with ClassifyOptions

use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyOptions in project java-sdk by watson-developer-cloud.

the class VisualRecognitionIT method testClassifyImagesFromBytes.

/**
 * Test classify a single jpg image.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testClassifyImagesFromBytes() throws IOException {
    InputStream imagesStream = new FileInputStream(SINGLE_IMAGE_FILE);
    ClassifyOptions options = new ClassifyOptions.Builder().imagesFile(imagesStream).imagesFilename("car.png").build();
    ClassifiedImages result = service.classify(options).execute();
    assertClassifyImage(result, options);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClassifyOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions) ClassifiedImages(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages) FileInputStream(java.io.FileInputStream) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 17 with ClassifyOptions

use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyOptions in project java-sdk by watson-developer-cloud.

the class VisualRecognitionTest method testClassifyWithFile.

/**
 * Test classify with file.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testClassifyWithFile() throws IOException, InterruptedException {
    ClassifiedImages mockResponse = loadFixture(FIXTURE_CLASSIFICATION, ClassifiedImages.class);
    server.enqueue(new MockResponse().setBody(mockResponse.toString()));
    // execute request
    File images = new File(IMAGE_FILE);
    ClassifyOptions options = new ClassifyOptions.Builder().imagesFile(images).classifierIds(Arrays.asList("car")).build();
    ClassifiedImages serviceResponse = service.classify(options).execute();
    // first request
    RecordedRequest request = server.takeRequest();
    String path = PATH_CLASSIFY + "?" + VERSION_DATE + "=2016-05-20&api_key=" + API_KEY;
    assertEquals(path, request.getPath());
    assertEquals("POST", request.getMethod());
    assertEquals(serviceResponse, mockResponse);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ClassifyOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions) ClassifiedImages(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages) File(java.io.File) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)13 ClassifyOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions)9 ClassifiedImages (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages)8 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)7 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)6 ClassifyOptions (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyOptions)5 File (java.io.File)5 Classification (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classification)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 JsonObject (com.google.gson.JsonObject)2 ClassificationCollection (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassificationCollection)2 ClassifyCollectionOptions (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyCollectionOptions)2 ClassifyInput (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyInput)2 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)2 Classifier (com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier)2 CreateClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 AssumptionViolatedException (org.junit.AssumptionViolatedException)2