use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class VisualRecognition method deleteClassifier.
/**
* Delete a classifier.
*
* @param deleteClassifierOptions the {@link DeleteClassifierOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a void result
*/
public ServiceCall<Void> deleteClassifier(DeleteClassifierOptions deleteClassifierOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteClassifierOptions, "deleteClassifierOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("classifier_id", deleteClassifierOptions.classifierId());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/classifiers/{classifier_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v3", "deleteClassifier");
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<Void> responseConverter = ResponseConverterUtils.getVoid();
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 updateClassifier.
/**
* Update a classifier.
*
* <p>Update a custom classifier by adding new positive or negative classes or by adding new
* images to existing classes. You must supply at least one set of positive or negative examples.
* For details, see [Updating custom
* classifiers](https://cloud.ibm.com/docs/visual-recognition?topic=visual-recognition-customizing#updating-custom-classifiers).
*
* <p>Encode all names in UTF-8 if they contain non-ASCII characters (.zip and image file names,
* and classifier and class names). The service assumes UTF-8 encoding if it encounters non-ASCII
* characters.
*
* <p>**Tips about retraining:**
*
* <p>- You can't update the classifier if the **X-Watson-Learning-Opt-Out** header parameter was
* set to `true` when the classifier was created. Training images are not stored in that case.
* Instead, create another classifier. For more information, see [Data
* collection](#data-collection).
*
* <p>- Don't make retraining calls on a classifier until the status is ready. When you submit
* retraining requests in parallel, the last request overwrites the previous requests. The
* `retrained` property shows the last time the classifier retraining finished.
*
* @param updateClassifierOptions the {@link UpdateClassifierOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Classifier}
*/
public ServiceCall<Classifier> updateClassifier(UpdateClassifierOptions updateClassifierOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(updateClassifierOptions, "updateClassifierOptions cannot be null");
com.ibm.cloud.sdk.core.util.Validator.isTrue((updateClassifierOptions.positiveExamples() != null) || (updateClassifierOptions.negativeExamples() != null), "At least one of positiveExamples or negativeExamples must be supplied.");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("classifier_id", updateClassifierOptions.classifierId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/classifiers/{classifier_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v3", "updateClassifier");
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));
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
if (updateClassifierOptions.positiveExamples() != null) {
for (Map.Entry<String, InputStream> entry : updateClassifierOptions.positiveExamples().entrySet()) {
String partName = String.format("%s_positive_examples", entry.getKey());
okhttp3.RequestBody part = RequestUtils.inputStreamBody(entry.getValue(), "application/octet-stream");
multipartBuilder.addFormDataPart(partName, entry.getKey(), part);
}
}
if (updateClassifierOptions.negativeExamples() != null) {
okhttp3.RequestBody negativeExamplesBody = RequestUtils.inputStreamBody(updateClassifierOptions.negativeExamples(), "application/octet-stream");
multipartBuilder.addFormDataPart("negative_examples", updateClassifierOptions.negativeExamplesFilename(), negativeExamplesBody);
}
builder.body(multipartBuilder.build());
ResponseConverter<Classifier> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Classifier>() {
}.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 getCoreMlModel.
/**
* Retrieve a Core ML model of a classifier.
*
* <p>Download a Core ML model file (.mlmodel) of a custom classifier that returns
* <tt>"core_ml_enabled": true</tt> in the classifier details.
*
* @param getCoreMlModelOptions the {@link GetCoreMlModelOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link InputStream}
*/
public ServiceCall<InputStream> getCoreMlModel(GetCoreMlModelOptions getCoreMlModelOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getCoreMlModelOptions, "getCoreMlModelOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("classifier_id", getCoreMlModelOptions.classifierId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/classifiers/{classifier_id}/core_ml_model", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v3", "getCoreMlModel");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/octet-stream");
builder.query("version", String.valueOf(this.version));
ResponseConverter<InputStream> responseConverter = ResponseConverterUtils.getInputStream();
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 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);
}
use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class ToneAnalyzer method toneChat.
/**
* Analyze customer-engagement tone.
*
* <p>Use the customer-engagement endpoint to analyze the tone of customer service and customer
* support conversations. For each utterance of a conversation, the method reports the most
* prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite,
* impolite, and sympathetic.
*
* <p>If you submit more than 50 utterances, the service returns a warning for the overall content
* and analyzes only the first 50 utterances. If you submit a single utterance that contains more
* than 500 characters, the service returns an error for that utterance and does not analyze the
* utterance. The request fails if all utterances have more than 500 characters. Per the JSON
* specification, the default character encoding for JSON content is effectively always UTF-8.
*
* <p>**See also:** [Using the customer-engagement
* endpoint](https://cloud.ibm.com/docs/tone-analyzer?topic=tone-analyzer-utco#utco).
*
* @param toneChatOptions the {@link ToneChatOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link UtteranceAnalyses}
*/
public ServiceCall<UtteranceAnalyses> toneChat(ToneChatOptions toneChatOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(toneChatOptions, "toneChatOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/tone_chat"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("tone_analyzer", "v3", "toneChat");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (toneChatOptions.contentLanguage() != null) {
builder.header("Content-Language", toneChatOptions.contentLanguage());
}
if (toneChatOptions.acceptLanguage() != null) {
builder.header("Accept-Language", toneChatOptions.acceptLanguage());
}
builder.query("version", String.valueOf(this.version));
final JsonObject contentJson = new JsonObject();
contentJson.add("utterances", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(toneChatOptions.utterances()));
builder.bodyJson(contentJson);
ResponseConverter<UtteranceAnalyses> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<UtteranceAnalyses>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations