Search in sources :

Example 1 with ClassifyInput

use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyInput 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();
    input1.setText("How hot will it be today?");
    ClassifyInput input2 = new ClassifyInput();
    input2.setText("Is it hot outside?");
    try {
        ClassifyCollectionOptions classifyOptions = new ClassifyCollectionOptions.Builder().classifierId(preCreatedClassifierId).addClassifyInput(input1).addClassifyInput(input2).build();
        classificationCollection = service.classifyCollection(classifyOptions).execute();
    } 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.developer_cloud.natural_language_classifier.v1.model.ClassificationCollection) ClassifyCollectionOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyCollectionOptions) AssumptionViolatedException(org.junit.AssumptionViolatedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ClassifyInput(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyInput) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with ClassifyInput

use of com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyInput 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)

Aggregations

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 Test (org.junit.Test)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 AssumptionViolatedException (org.junit.AssumptionViolatedException)1