Search in sources :

Example 16 with Collection

use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.

the class VisualRecognition method train.

/**
 * Train a collection.
 *
 * <p>Start training on images in a collection. The collection must have enough training data and
 * untrained data (the **training_status.objects.data_changed** is `true`). If training is in
 * progress, the request queues the next training job.
 *
 * @param trainOptions the {@link TrainOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Collection}
 */
public ServiceCall<Collection> train(TrainOptions trainOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(trainOptions, "trainOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("collection_id", trainOptions.collectionId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}/train", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "train");
    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<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Collection(com.ibm.watson.visual_recognition.v4.model.Collection)

Example 17 with Collection

use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.

the class VisualRecognition method createCollection.

/**
 * Create a collection.
 *
 * <p>Create a collection that can be used to store images.
 *
 * <p>To create a collection without specifying a name and description, include an empty JSON
 * object in the request body.
 *
 * <p>Encode the name and description in UTF-8 if they contain non-ASCII characters. The service
 * assumes UTF-8 encoding if it encounters non-ASCII characters.
 *
 * @param createCollectionOptions the {@link CreateCollectionOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Collection}
 */
public ServiceCall<Collection> createCollection(CreateCollectionOptions createCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createCollectionOptions, "createCollectionOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "createCollection");
    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));
    final JsonObject contentJson = new JsonObject();
    if (createCollectionOptions.name() != null) {
        contentJson.addProperty("name", createCollectionOptions.name());
    }
    if (createCollectionOptions.description() != null) {
        contentJson.addProperty("description", createCollectionOptions.description());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Collection(com.ibm.watson.visual_recognition.v4.model.Collection)

Example 18 with Collection

use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.

the class VisualRecognition method getCollection.

/**
 * Get collection details.
 *
 * <p>Get details of one collection.
 *
 * @param getCollectionOptions the {@link GetCollectionOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Collection}
 */
public ServiceCall<Collection> getCollection(GetCollectionOptions getCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getCollectionOptions, "getCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("collection_id", getCollectionOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "getCollection");
    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<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Collection(com.ibm.watson.visual_recognition.v4.model.Collection)

Example 19 with Collection

use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.

the class VisualRecognitionTest method testUpdateCollectionWOptions.

@Test
public void testUpdateCollectionWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"collection_id\": \"collectionId\", \"name\": \"name\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"image_count\": 10, \"training_status\": {\"objects\": {\"ready\": false, \"in_progress\": true, \"data_changed\": false, \"latest_failed\": true, \"rscnn_ready\": true, \"description\": \"description\"}}}";
    String updateCollectionPath = "/v4/collections/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the UpdateCollectionOptions model
    UpdateCollectionOptions updateCollectionOptionsModel = new UpdateCollectionOptions.Builder().collectionId("testString").name("testString").description("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<Collection> response = visualRecognitionService.updateCollection(updateCollectionOptionsModel).execute();
    assertNotNull(response);
    Collection responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, updateCollectionPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UpdateCollectionOptions(com.ibm.watson.visual_recognition.v4.model.UpdateCollectionOptions) Collection(com.ibm.watson.visual_recognition.v4.model.Collection) Test(org.testng.annotations.Test)

Example 20 with Collection

use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceTest method getCollectionIsSuccessful.

/**
 * Gets the collection is successful.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void getCollectionIsSuccessful() throws InterruptedException {
    server.enqueue(jsonResponse(getCollResp));
    GetCollectionOptions getRequest = new GetCollectionOptions.Builder(environmentId, collectionId).build();
    Collection response = discoveryService.getCollection(getRequest).execute().getResult();
    RecordedRequest request = server.takeRequest();
    assertEquals(COLL2_PATH, request.getPath());
    assertEquals(GET, request.getMethod());
    assertEquals(getCollResp, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetCollectionOptions(com.ibm.watson.discovery.v1.model.GetCollectionOptions) Collection(com.ibm.watson.discovery.v1.model.Collection) WatsonServiceUnitTest(com.ibm.watson.common.WatsonServiceUnitTest)

Aggregations

Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)26 Test (org.junit.Test)22 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)18 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)11 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)11 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)10 JsonObject (com.google.gson.JsonObject)9 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)9 Collection (com.ibm.watson.discovery.v1.model.Collection)9 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 MockResponse (okhttp3.mockwebserver.MockResponse)7 Test (org.testng.annotations.Test)7 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)6 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)5 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)5 QueryResponse (com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse)5 HashMap (java.util.HashMap)5