Search in sources :

Example 11 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 NaturalLanguageClassifierTest method testClassifyCollection.

/**
 * Test classifying a collection.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testClassifyCollection() throws InterruptedException {
    final String path = String.format(CLASSIFY_COLLECTION_PATH, classifierId);
    server.enqueue(jsonResponse(classificationCollection));
    ClassifyInput input1 = new ClassifyInput();
    input1.setText("How hot will it be today?");
    ClassifyInput input2 = new ClassifyInput();
    input2.setText("Is it hot outside?");
    List<ClassifyInput> inputCollection = Arrays.asList(input1, input2);
    ClassifyCollectionOptions classifyOptions = new ClassifyCollectionOptions.Builder().classifierId(classifierId).collection(inputCollection).build();
    final ClassificationCollection result = service.classifyCollection(classifyOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(path, request.getPath());
    assertEquals("POST", request.getMethod());
    assertEquals(classificationCollection, result);
}
Also used : ClassificationCollection(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassificationCollection) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ClassifyCollectionOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyCollectionOptions) ClassifyInput(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyInput) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 12 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 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 13 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 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 14 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 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 15 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 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)

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