Search in sources :

Example 6 with ClassificationCollection

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

the class NaturalLanguageClassifierIT method fClassifyCollection.

/**
 * Test classifyCollection. Use the pre created classifier to avoid waiting for availability
 */
@Test
public void fClassifyCollection() {
    ClassificationCollection classificationCollection = null;
    ClassifyInput input1 = new ClassifyInput.Builder().text("How hot will it be today?").build();
    ClassifyInput input2 = new ClassifyInput.Builder().text("Is it hot outside?").build();
    try {
        ClassifyCollectionOptions classifyOptions = new ClassifyCollectionOptions.Builder().classifierId(preCreatedClassifierId).addClassifyInput(input1).addClassifyInput(input2).build();
        classificationCollection = service.classifyCollection(classifyOptions).execute().getResult();
    } catch (NotFoundException e) {
        // The build should not fail here, because this is out of our control.
        throw new AssumptionViolatedException(e.getMessage(), e);
    }
    assertNotNull(classificationCollection);
    assertEquals("temperature", classificationCollection.getCollection().get(0).getTopClass());
    assertEquals("temperature", classificationCollection.getCollection().get(1).getTopClass());
}
Also used : ClassificationCollection(com.ibm.watson.natural_language_classifier.v1.model.ClassificationCollection) ClassifyCollectionOptions(com.ibm.watson.natural_language_classifier.v1.model.ClassifyCollectionOptions) AssumptionViolatedException(org.junit.AssumptionViolatedException) NotFoundException(com.ibm.cloud.sdk.core.service.exception.NotFoundException) ClassifyInput(com.ibm.watson.natural_language_classifier.v1.model.ClassifyInput) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Aggregations

ClassificationCollection (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassificationCollection)3 ClassificationCollection (com.ibm.watson.natural_language_classifier.v1.model.ClassificationCollection)3 Test (org.junit.Test)3 JsonObject (com.google.gson.JsonObject)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 ClassifyCollectionOptions (com.ibm.watson.natural_language_classifier.v1.model.ClassifyCollectionOptions)2 ClassifyInput (com.ibm.watson.natural_language_classifier.v1.model.ClassifyInput)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 AssumptionViolatedException (org.junit.AssumptionViolatedException)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)1 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)1 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 Test (org.testng.annotations.Test)1