Search in sources :

Example 61 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder 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 62 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder 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 63 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class VisualRecognition method listObjectMetadata.

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

Example 64 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class VisualRecognition method updateObjectMetadata.

/**
 * Update an object name.
 *
 * <p>Update the name of an object. A successful request updates the training data for all images
 * that use the object.
 *
 * @param updateObjectMetadataOptions the {@link UpdateObjectMetadataOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link UpdateObjectMetadata}
 */
public ServiceCall<UpdateObjectMetadata> updateObjectMetadata(UpdateObjectMetadataOptions updateObjectMetadataOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateObjectMetadataOptions, "updateObjectMetadataOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("collection_id", updateObjectMetadataOptions.collectionId());
    pathParamsMap.put("object", updateObjectMetadataOptions.object());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}/objects/{object}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "updateObjectMetadata");
    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();
    contentJson.addProperty("object", updateObjectMetadataOptions.newObject());
    builder.bodyJson(contentJson);
    ResponseConverter<UpdateObjectMetadata> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<UpdateObjectMetadata>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) UpdateObjectMetadata(com.ibm.watson.visual_recognition.v4.model.UpdateObjectMetadata)

Example 65 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class VisualRecognition method getJpegImage.

/**
 * Get a JPEG file of an image.
 *
 * <p>Download a JPEG representation of an image.
 *
 * @param getJpegImageOptions the {@link GetJpegImageOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link InputStream}
 */
public ServiceCall<InputStream> getJpegImage(GetJpegImageOptions getJpegImageOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getJpegImageOptions, "getJpegImageOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("collection_id", getJpegImageOptions.collectionId());
    pathParamsMap.put("image_id", getJpegImageOptions.imageId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}/images/{image_id}/jpeg", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "getJpegImage");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "image/jpeg");
    builder.query("version", String.valueOf(this.version));
    if (getJpegImageOptions.size() != null) {
        builder.query("size", String.valueOf(getJpegImageOptions.size()));
    }
    ResponseConverter<InputStream> responseConverter = ResponseConverterUtils.getInputStream();
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) InputStream(java.io.InputStream)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)422 HashMap (java.util.HashMap)324 JsonObject (com.google.gson.JsonObject)111 MultipartBody (okhttp3.MultipartBody)30 InputStream (java.io.InputStream)27 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)12 Ok (com.ibm.cloud.cloudant.v1.model.Ok)8 MetricResponse (com.ibm.watson.discovery.v1.model.MetricResponse)4 DeleteModelResults (com.ibm.watson.natural_language_understanding.v1.model.DeleteModelResults)4 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)4 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)3 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)3 TagsSubscriptionList (com.ibm.cloud.eventnotifications.event_notifications.v1.model.TagsSubscriptionList)3 Counterexample (com.ibm.watson.assistant.v1.model.Counterexample)3 DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)3 Entity (com.ibm.watson.assistant.v1.model.Entity)3 Intent (com.ibm.watson.assistant.v1.model.Intent)3 Value (com.ibm.watson.assistant.v1.model.Value)3 DeleteCredentials (com.ibm.watson.discovery.v1.model.DeleteCredentials)3 TokenDictStatusResponse (com.ibm.watson.discovery.v1.model.TokenDictStatusResponse)3