Search in sources :

Example 71 with RequestBuilder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Example 72 with RequestBuilder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) InputStream(java.io.InputStream) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) Classifier(com.ibm.watson.visual_recognition.v3.model.Classifier) MultipartBody(okhttp3.MultipartBody) HashMap(java.util.HashMap) Map(java.util.Map)

Example 73 with RequestBuilder

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
 * &lt;tt&gt;"core_ml_enabled": true&lt;/tt&gt; 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) InputStream(java.io.InputStream)

Example 74 with RequestBuilder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Classifier(com.ibm.watson.visual_recognition.v3.model.Classifier)

Example 75 with RequestBuilder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) UtteranceAnalyses(com.ibm.watson.tone_analyzer.v3.model.UtteranceAnalyses)

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