Search in sources :

Example 16 with ClassifyOptions

use of com.ibm.watson.visual_recognition.v3.model.ClassifyOptions in project java-sdk by watson-developer-cloud.

the class NaturalLanguageClassifierTest method testClassify.

/**
 * Test classify.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testClassify() throws InterruptedException {
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty(TEXT, classification.getText());
    final String path = String.format(CLASSIFY_PATH, classifierId);
    server.enqueue(jsonResponse(classification));
    ClassifyOptions classifyOptions = new ClassifyOptions.Builder().classifierId(classifierId).text(classification.getText()).build();
    final Classification result = service.classify(classifyOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(path, request.getPath());
    assertEquals("POST", request.getMethod());
    assertEquals(contentJson.toString(), request.getBody().readUtf8());
    assertEquals(classification, result);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ClassifyOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyOptions) Classification(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classification) JsonObject(com.google.gson.JsonObject) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 17 with ClassifyOptions

use of com.ibm.watson.visual_recognition.v3.model.ClassifyOptions in project java-sdk by watson-developer-cloud.

the class VisualRecognitionIT method testClassifyImagesFromUrl.

/**
 * Test classify images from url.
 */
@Test
public void testClassifyImagesFromUrl() {
    ClassifyOptions options = new ClassifyOptions.Builder().url(IMAGE_URL).build();
    ClassifiedImages result = service.classify(options).execute();
    assertClassifyImage(result, options);
}
Also used : ClassifyOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions) ClassifiedImages(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 18 with ClassifyOptions

use of com.ibm.watson.visual_recognition.v3.model.ClassifyOptions in project java-sdk by watson-developer-cloud.

the class VisualRecognitionIT method testClassifyImagesFromFile.

/**
 * Test classify images from zip file.
 */
@Test
public void testClassifyImagesFromFile() throws FileNotFoundException {
    File images = new File(IMAGE_FILE);
    ClassifyOptions options = new ClassifyOptions.Builder().imagesFile(images).build();
    ClassifiedImages result = service.classify(options).execute();
    assertClassifyImage(result, options);
}
Also used : 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) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 19 with ClassifyOptions

use of com.ibm.watson.visual_recognition.v3.model.ClassifyOptions in project java-sdk by watson-developer-cloud.

the class VisualRecognitionIT method testClassifyImagesFromUrlUsingParameters.

/**
 * Test classify images from url using the deprecated parameters option.
 */
@Test
public void testClassifyImagesFromUrlUsingParameters() {
    String parameters = "{\"url\":\"" + IMAGE_URL + "\"}";
    ClassifyOptions options = new ClassifyOptions.Builder().parameters(parameters).build();
    ClassifiedImages result = service.classify(options).execute();
    assertClassifyImage(result, options);
}
Also used : ClassifyOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions) ClassifiedImages(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 20 with ClassifyOptions

use of com.ibm.watson.visual_recognition.v3.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)

Aggregations

Test (org.junit.Test)16 ClassifyOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions)9 ClassifiedImages (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages)8 File (java.io.File)7 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)6 ClassifiedImages (com.ibm.watson.visual_recognition.v3.model.ClassifiedImages)6 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)5 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)5 ClassifyOptions (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyOptions)5 ClassifyOptions (com.ibm.watson.visual_recognition.v3.model.ClassifyOptions)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)5 MockResponse (okhttp3.mockwebserver.MockResponse)4 Classification (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classification)3 Classification (com.ibm.watson.natural_language_classifier.v1.model.Classification)3 ClassifyOptions (com.ibm.watson.natural_language_classifier.v1.model.ClassifyOptions)3 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 Classifier (com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier)2 CreateClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions)2 AssumptionViolatedException (org.junit.AssumptionViolatedException)2