Search in sources :

Example 6 with GetClassifierOptions

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

the class VisualRecognition method getClassifier.

/**
 * Retrieve classifier details.
 *
 * <p>Retrieve information about a custom classifier.
 *
 * @param getClassifierOptions the {@link GetClassifierOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Classifier}
 */
public ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getClassifierOptions, "getClassifierOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("classifier_id", getClassifierOptions.classifierId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/classifiers/{classifier_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v3", "getClassifier");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<Classifier> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Classifier>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Classifier(com.ibm.watson.visual_recognition.v3.model.Classifier)

Example 7 with GetClassifierOptions

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

the class NaturalLanguageClassifierIT method bGetClassifier.

/**
 * Test get classifier.
 */
@Test
public void bGetClassifier() {
    final Classifier classifier;
    try {
        GetClassifierOptions getOptions = new GetClassifierOptions.Builder().classifierId(classifierId).build();
        classifier = service.getClassifier(getOptions).execute();
    } catch (NotFoundException e) {
        // The build should not fail here, because this is out of our control.
        throw new AssumptionViolatedException(e.getMessage(), e);
    }
    assertNotNull(classifier);
    assertEquals(classifierId, classifier.getClassifierId());
    assertEquals(Classifier.Status.TRAINING, classifier.getStatus());
}
Also used : GetClassifierOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.GetClassifierOptions) AssumptionViolatedException(org.junit.AssumptionViolatedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Classifier(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 8 with GetClassifierOptions

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

the class NaturalLanguageClassifierTest method testGetClassifier.

/**
 * Test get classifier.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testGetClassifier() throws InterruptedException {
    server.enqueue(jsonResponse(classifier));
    GetClassifierOptions getOptions = new GetClassifierOptions.Builder().classifierId(classifierId).build();
    final Classifier response = service.getClassifier(getOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(CLASSIFIERS_PATH + "/" + classifierId, request.getPath());
    assertEquals(classifier, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetClassifierOptions(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.GetClassifierOptions) Classifier(com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier) Test(org.junit.Test) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest)

Example 9 with GetClassifierOptions

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

the class VisualRecognitionTest method testGetClassifier.

/**
 * Test get classifier.
 *
 * @throws InterruptedException the interrupted exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void testGetClassifier() throws InterruptedException, IOException {
    try {
        Classifier mockResponse = loadFixture(FIXTURE_CLASSIFIER, Classifier.class);
        server.enqueue(new MockResponse().setBody(mockResponse.toString()));
        // execute request
        String class1 = "class1";
        GetClassifierOptions getOptions = new GetClassifierOptions.Builder(class1).build();
        Classifier serviceResponse = service.getClassifier(getOptions).execute();
        // first request
        RecordedRequest request = server.takeRequest();
        String path = String.format(PATH_CLASSIFIER + "?" + VERSION_DATE + "=2016-05-20&api_key=" + API_KEY, class1);
        assertEquals(path, request.getPath());
        assertEquals("GET", request.getMethod());
        assertEquals(serviceResponse, mockResponse);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetClassifierOptions(com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions) Classifier(com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier) IOException(java.io.IOException) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 10 with GetClassifierOptions

use of com.ibm.watson.visual_recognition.v3.model.GetClassifierOptions 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
 */
@Test
public void testCreateClassifier() throws FileNotFoundException, InterruptedException {
    String classifierName = "integration-test-java-sdk";
    String carClassifier = "car";
    File carImages = new File("src/test/resources/visual_recognition/v3/car_positive.zip");
    InputStream negativeImages = new FileInputStream("src/test/resources/visual_recognition/v3/negative.zip");
    CreateClassifierOptions.Builder builder = new CreateClassifierOptions.Builder().name(classifierName);
    builder.addPositiveExamples(carClassifier, carImages);
    builder.negativeExamples(negativeImages);
    builder.negativeExamplesFilename("negative.zip");
    Classifier newClass = service.createClassifier(builder.build()).execute().getResult();
    try {
        assertEquals(classifierName, newClass.getName());
        boolean ready = false;
        for (int x = 0; (x < 40) && !ready; x++) {
            Thread.sleep(2000);
            GetClassifierOptions getOptions = new GetClassifierOptions.Builder(newClass.getClassifierId()).build();
            newClass = service.getClassifier(getOptions).execute().getResult();
            ready = newClass.getStatus().equals(Status.READY);
        }
        // if it at least hasn't failed, we're probably fine
        assertNotEquals(Status.FAILED, newClass.getStatus());
    } finally {
        DeleteClassifierOptions deleteOptions = new DeleteClassifierOptions.Builder(newClass.getClassifierId()).build();
        service.deleteClassifier(deleteOptions).execute();
    }
}
Also used : DeleteClassifierOptions(com.ibm.watson.visual_recognition.v3.model.DeleteClassifierOptions) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Classifier(com.ibm.watson.visual_recognition.v3.model.Classifier) FileInputStream(java.io.FileInputStream) GetClassifierOptions(com.ibm.watson.visual_recognition.v3.model.GetClassifierOptions) CreateClassifierOptions(com.ibm.watson.visual_recognition.v3.model.CreateClassifierOptions) File(java.io.File) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 Classifier (com.ibm.watson.visual_recognition.v3.model.Classifier)4 File (java.io.File)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)3 Classifier (com.ibm.watson.developer_cloud.visual_recognition.v3.model.Classifier)3 GetClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.GetClassifierOptions)3 GetClassifierOptions (com.ibm.watson.visual_recognition.v3.model.GetClassifierOptions)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 Ignore (org.junit.Ignore)3 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 Classifier (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classifier)2 GetClassifierOptions (com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.GetClassifierOptions)2 CreateClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.CreateClassifierOptions)2 DeleteClassifierOptions (com.ibm.watson.developer_cloud.visual_recognition.v3.model.DeleteClassifierOptions)2 Classifier (com.ibm.watson.natural_language_classifier.v1.model.Classifier)2 GetClassifierOptions (com.ibm.watson.natural_language_classifier.v1.model.GetClassifierOptions)2 CreateClassifierOptions (com.ibm.watson.visual_recognition.v3.model.CreateClassifierOptions)2 DeleteClassifierOptions (com.ibm.watson.visual_recognition.v3.model.DeleteClassifierOptions)2