Search in sources :

Example 1 with CreateClassifierOptions

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

the class NaturalLanguageClassifierIT method aCreate.

/**
 * Creates the classifier.
 *
 * @throws Exception the exception
 */
@Test
public void aCreate() throws Exception {
    final File trainingData = new File("src/test/resources/natural_language_classifier/weather_data_train.csv");
    final File metadata = new File("src/test/resources/natural_language_classifier/metadata.json");
    CreateClassifierOptions createOptions = new CreateClassifierOptions.Builder().metadata(metadata).trainingData(trainingData).trainingDataFilename("weather_data_train.csv").build();
    Classifier classifier = service.createClassifier(createOptions).execute();
    try {
        assertNotNull(classifier);
        assertEquals(Status.TRAINING, classifier.getStatus());
        assertEquals("test-classifier", classifier.getName());
        assertEquals("en", classifier.getLanguage());
    } finally {
        classifierId = classifier.getClassifierId();
    }
}
Also used : 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) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with CreateClassifierOptions

use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions 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 3 with CreateClassifierOptions

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

the class NaturalLanguageClassifier method createClassifier.

/**
 * Create classifier.
 *
 * This method is here for backwards-compatibility with the old version of createClassifier.
 *
 * @param name the classifier name
 * @param language IETF primary language for the classifier. for example: 'en'
 * @param trainingData the set of questions and their "keys" used to adapt a system to a domain (the ground truth)
 * @return the classifier
 * @throws FileNotFoundException if the file could not be found
 */
public ServiceCall<Classifier> createClassifier(String name, String language, File trainingData) throws FileNotFoundException {
    Map<String, String> metadataMap = new HashMap<>();
    metadataMap.put("name", name);
    metadataMap.put("language", language);
    String metadataString = GsonSingleton.getGson().toJson(metadataMap);
    CreateClassifierOptions createClassifierOptions = new CreateClassifierOptions.Builder().metadata(new ByteArrayInputStream(metadataString.getBytes())).trainingData(trainingData).build();
    return createClassifier(createClassifierOptions);
}
Also used : CreateClassifierOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.CreateClassifierOptions) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 4 with CreateClassifierOptions

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

the class VisualRecognitionExample method main.

public static void main(String[] args) {
    VisualRecognition service = new VisualRecognition("2016-05-20");
    service.setApiKey("<api-key>");
    System.out.println("Classify an image");
    ClassifyOptions options = new ClassifyOptions.Builder().imagesFile(new File("src/test/resources/visual_recognition/car.png")).imagesFilename("car.png").build();
    ClassifiedImages result = service.classify(options).execute();
    System.out.println(result);
    System.out.println("Create a classifier with positive and negative images");
    CreateClassifierOptions createOptions = new CreateClassifierOptions.Builder().name("foo").addClass("car", new File("src/test/resources/visual_recognition/car_positive.zip")).addClass("baseball", new File("src/test/resources/visual_recognition/baseball_positive.zip")).negativeExamples(new File("src/test/resources/visual_recognition/negative.zip")).build();
    Classifier foo = service.createClassifier(createOptions).execute();
    System.out.println(foo);
    System.out.println("Classify using the 'Car' classifier");
    options = new ClassifyOptions.Builder().imagesFile(new File("src/test/resources/visual_recognition/car.png")).imagesFilename("car.png").addClassifierId(foo.getClassifierId()).build();
    result = service.classify(options).execute();
    System.out.println(result);
    System.out.println("Update a classifier with more positive images");
    UpdateClassifierOptions updateOptions = new UpdateClassifierOptions.Builder().classifierId(foo.getClassifierId()).addClass("car", new File("src/test/resources/visual_recognition/car_positive.zip")).build();
    Classifier updatedFoo = service.updateClassifier(updateOptions).execute();
    System.out.println(updatedFoo);
}
Also used : CreateClassifierOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions) ClassifyOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifyOptions) UpdateClassifierOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.UpdateClassifierOptions) Classifier(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier) ClassifiedImages(com.ibm.watson.developer_cloud.visual_recognition.v3.model.ClassifiedImages) File(java.io.File)

Example 5 with CreateClassifierOptions

use of com.ibm.watson.developer_cloud.visual_recognition.v3.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)

Aggregations

File (java.io.File)6 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.visual_recognition.v3.model.Classifier)3 Classifier (com.ibm.watson.developer_cloud.natural_language_classifier.v1.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