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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations