Search in sources :

Example 6 with Classifier

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

the class NaturalLanguageClassifierTest method testNullDeleteClassifier.

/**
 * Test null delete classifier.
 */
@Test(expected = IllegalArgumentException.class)
public void testNullDeleteClassifier() {
    DeleteClassifierOptions deleteOptions = new DeleteClassifierOptions.Builder().build();
    service.deleteClassifier(deleteOptions);
}
Also used : DeleteClassifierOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.DeleteClassifierOptions) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 7 with Classifier

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

the class NaturalLanguageClassifierTest method testCreateClassifier.

/**
 * Test create classifier.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testCreateClassifier() throws InterruptedException, FileNotFoundException {
    server.enqueue(jsonResponse(classifier));
    File metadata = new File(RESOURCE + "metadata.json");
    File trainingData = new File(RESOURCE + "weather_data_train.csv");
    CreateClassifierOptions createOptions = new CreateClassifierOptions.Builder().metadata(metadata).trainingData(trainingData).trainingDataFilename("weather_data_train.csv").build();
    final Classifier response = service.createClassifier(createOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(CLASSIFIERS_PATH, request.getPath());
    assertEquals(classifier, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) CreateClassifierOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.CreateClassifierOptions) Classifier(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier) File(java.io.File) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 8 with Classifier

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

the class NaturalLanguageClassifierTest method testDeleteClassifier.

/**
 * Test delete classifier.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testDeleteClassifier() throws InterruptedException {
    DeleteClassifierOptions deleteOptions = new DeleteClassifierOptions.Builder().classifierId(classifierId).build();
    service.deleteClassifier(deleteOptions);
}
Also used : DeleteClassifierOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.DeleteClassifierOptions) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 9 with Classifier

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

the class NaturalLanguageClassifierTest method testNullClassifier.

// START NEGATIVE TESTS
/**
 * Test null classifier.
 */
@Test(expected = IllegalArgumentException.class)
public void testNullClassifier() {
    ClassifyOptions classifyOptions = new ClassifyOptions.Builder().text("test").build();
    service.classify(classifyOptions);
}
Also used : ClassifyOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyOptions) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 10 with Classifier

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

the class VisualRecognitionIT method testCreateClassifier.

/**
 * Test create a classifier.
 *
 * @throws FileNotFoundException the file not found exception
 * @throws InterruptedException the interrupted exception
 */
@Ignore
@Test
public void testCreateClassifier() throws FileNotFoundException, InterruptedException {
    String classifierName = "integration-test-java-sdk";
    String carClassifier = "car";
    String baseballClassifier = "baseball";
    File carImages = new File("src/test/resources/visual_recognition/car_positive.zip");
    File baseballImages = new File("src/test/resources/visual_recognition/baseball_positive.zip");
    InputStream negativeImages = new FileInputStream("src/test/resources/visual_recognition/negative.zip");
    CreateClassifierOptions.Builder builder = new CreateClassifierOptions.Builder().name(classifierName);
    builder.addClass(carClassifier, carImages);
    builder.addClass(baseballClassifier, baseballImages);
    builder.negativeExamples(negativeImages);
    builder.negativeExamplesFilename("negative.zip");
    Classifier newClass = service.createClassifier(builder.build()).execute();
    try {
        assertEquals(classifierName, newClass.getName());
        boolean ready = false;
        for (int x = 0; (x < 20) && !ready; x++) {
            Thread.sleep(2000);
            GetClassifierOptions getOptions = new GetClassifierOptions.Builder(newClass.getClassifierId()).build();
            newClass = service.getClassifier(getOptions).execute();
            ready = newClass.getStatus().equals(Status.READY);
        }
        assertEquals(Status.READY, newClass.getStatus());
    } finally {
        DeleteClassifierOptions deleteOptions = new DeleteClassifierOptions.Builder(newClass.getClassifierId()).build();
        service.deleteClassifier(deleteOptions).execute();
    }
}
Also used : DeleteClassifierOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.DeleteClassifierOptions) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Classifier(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier) FileInputStream(java.io.FileInputStream) GetClassifierOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions) CreateClassifierOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions) File(java.io.File) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 Classifier (com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier)13 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)10 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)10 File (java.io.File)10 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)7 Classifier (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier)7 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 Ignore (org.junit.Ignore)5 CreateClassifierOptions (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.CreateClassifierOptions)4 CreateClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 JsonObject (com.google.gson.JsonObject)3 DeleteClassifierOptions (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.DeleteClassifierOptions)3 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)3 DeleteClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.DeleteClassifierOptions)3 GetClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions)3 ListClassifiersOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ListClassifiersOptions)3 MultipartBody (okhttp3.MultipartBody)3 RequestBody (okhttp3.RequestBody)3