Search in sources :

Example 6 with CreateClassifierOptions

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

the class NaturalLanguageClassifierTest method testNullTrainingDataFile.

/**
 * Test null training data file.
 */
@Test(expected = FileNotFoundException.class)
public void testNullTrainingDataFile() throws FileNotFoundException {
    server.enqueue(jsonResponse(classifier));
    File metadata = new File(RESOURCE + "metadata.json");
    File trainingData = new File(RESOURCE + "notfound.txt");
    CreateClassifierOptions createOptions = new CreateClassifierOptions.Builder().metadata(metadata).trainingData(trainingData).trainingDataFilename("notfound.txt").build();
    service.createClassifier(createOptions).execute();
}
Also used : CreateClassifierOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.CreateClassifierOptions) File(java.io.File) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 7 with CreateClassifierOptions

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

the class VisualRecognitionTest method testCreateClassifier.

/**
 * Test create classifier.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testCreateClassifier() throws IOException, InterruptedException {
    Classifier mockResponse = loadFixture(FIXTURE_CLASSIFIER, Classifier.class);
    server.enqueue(new MockResponse().setBody(mockResponse.toString()));
    // execute request
    File positiveImages = new File(IMAGE_FILE);
    File negativeImages = new File(IMAGE_FILE);
    String class1 = "class1";
    CreateClassifierOptions options = new CreateClassifierOptions.Builder().name(class1).addClass(class1, positiveImages).negativeExamples(negativeImages).build();
    Classifier serviceResponse = service.createClassifier(options).execute();
    // first request
    RecordedRequest request = server.takeRequest();
    String path = PATH_CLASSIFIERS + "?" + VERSION_DATE + "=2016-05-20&api_key=" + API_KEY;
    assertEquals(path, request.getPath());
    assertEquals("POST", request.getMethod());
    String body = request.getBody().readUtf8();
    String contentDisposition = "Content-Disposition: form-data; name=\"class1_positive_examples\"; filename=\"test.zip\"";
    assertTrue(body.contains(contentDisposition));
    assertTrue(body.contains("Content-Disposition: form-data; name=\"name\""));
    assertEquals(serviceResponse, mockResponse);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CreateClassifierOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions) Classifier(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier) File(java.io.File) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

File (java.io.File)5 CreateClassifierOptions (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.CreateClassifierOptions)4 Test (org.junit.Test)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)3 Classifier (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier)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 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 ClassifiedImages (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages)1 ClassifyOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions)1 UpdateClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.UpdateClassifierOptions)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashMap (java.util.HashMap)1 MultipartBody (okhttp3.MultipartBody)1 RequestBody (okhttp3.RequestBody)1 MockResponse (okhttp3.mockwebserver.MockResponse)1