Search in sources :

Example 96 with RequestBuilder

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

the class LanguageTranslator method listModels.

/**
 * List models.
 *
 * Lists available translation models.
 *
 * @param listModelsOptions the {@link ListModelsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link TranslationModels}
 */
public ServiceCall<TranslationModels> listModels(ListModelsOptions listModelsOptions) {
    String[] pathSegments = { "v2/models" };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    if (listModelsOptions != null) {
        if (listModelsOptions.source() != null) {
            builder.query("source", listModelsOptions.source());
        }
        if (listModelsOptions.target() != null) {
            builder.query("target", listModelsOptions.target());
        }
        if (listModelsOptions.defaultModels() != null) {
            builder.query("default", String.valueOf(listModelsOptions.defaultModels()));
        }
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TranslationModels.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) TranslationModels(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModels)

Example 97 with RequestBuilder

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

the class LanguageTranslator method createModel.

/**
 * Create model.
 *
 * Uploads a TMX glossary file on top of a domain to customize a translation model. Depending on the size of the file,
 * training can range from minutes for a glossary to several hours for a large parallel corpus. Glossary files must be
 * less than 10 MB. The cumulative file size of all uploaded glossary and corpus files is limited to 250 MB.
 *
 * @param createModelOptions the {@link CreateModelOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link TranslationModel}
 */
public ServiceCall<TranslationModel> createModel(CreateModelOptions createModelOptions) {
    Validator.notNull(createModelOptions, "createModelOptions cannot be null");
    Validator.isTrue((createModelOptions.forcedGlossary() != null) || (createModelOptions.parallelCorpus() != null) || (createModelOptions.monolingualCorpus() != null), "At least one of forcedGlossary, parallelCorpus, or monolingualCorpus must be supplied.");
    String[] pathSegments = { "v2/models" };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    builder.query("base_model_id", createModelOptions.baseModelId());
    if (createModelOptions.name() != null) {
        builder.query("name", createModelOptions.name());
    }
    MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
    multipartBuilder.setType(MultipartBody.FORM);
    if (createModelOptions.forcedGlossary() != null) {
        RequestBody forcedGlossaryBody = RequestUtils.inputStreamBody(createModelOptions.forcedGlossary(), "application/octet-stream");
        multipartBuilder.addFormDataPart("forced_glossary", createModelOptions.forcedGlossaryFilename(), forcedGlossaryBody);
    }
    if (createModelOptions.parallelCorpus() != null) {
        RequestBody parallelCorpusBody = RequestUtils.inputStreamBody(createModelOptions.parallelCorpus(), "application/octet-stream");
        multipartBuilder.addFormDataPart("parallel_corpus", createModelOptions.parallelCorpusFilename(), parallelCorpusBody);
    }
    if (createModelOptions.monolingualCorpus() != null) {
        RequestBody monolingualCorpusBody = RequestUtils.inputStreamBody(createModelOptions.monolingualCorpus(), "text/plain");
        multipartBuilder.addFormDataPart("monolingual_corpus", createModelOptions.monolingualCorpusFilename(), monolingualCorpusBody);
    }
    builder.body(multipartBuilder.build());
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TranslationModel.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) TranslationModel(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel) MultipartBody(okhttp3.MultipartBody) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) RequestBody(okhttp3.RequestBody)

Example 98 with RequestBuilder

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

the class Discovery method createConfiguration.

/**
 * Add configuration.
 *
 * Creates a new configuration. If the input configuration contains the `configuration_id`, `created`, or `updated`
 * properties, then they are ignored and overridden by the system, and an error is not returned so that the overridden
 * fields do not need to be removed when copying a configuration. The configuration can contain unrecognized JSON
 * fields. Any such fields are ignored and do not generate an error. This makes it easier to use newer configuration
 * files with older versions of the API and the service. It also makes it possible for the tooling to add additional
 * metadata and information to the configuration.
 *
 * @param createConfigurationOptions the {@link CreateConfigurationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Configuration}
 */
public ServiceCall<Configuration> createConfiguration(CreateConfigurationOptions createConfigurationOptions) {
    Validator.notNull(createConfigurationOptions, "createConfigurationOptions cannot be null");
    String[] pathSegments = { "v1/environments", "configurations" };
    String[] pathParameters = { createConfigurationOptions.environmentId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (createConfigurationOptions.name() != null) {
        contentJson.addProperty("name", createConfigurationOptions.name());
    }
    if (createConfigurationOptions.description() != null) {
        contentJson.addProperty("description", createConfigurationOptions.description());
    }
    if (createConfigurationOptions.conversions() != null) {
        contentJson.add("conversions", GsonSingleton.getGson().toJsonTree(createConfigurationOptions.conversions()));
    }
    if (createConfigurationOptions.enrichments() != null) {
        contentJson.add("enrichments", GsonSingleton.getGson().toJsonTree(createConfigurationOptions.enrichments()));
    }
    if (createConfigurationOptions.normalizations() != null) {
        contentJson.add("normalizations", GsonSingleton.getGson().toJsonTree(createConfigurationOptions.normalizations()));
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Configuration.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) JsonObject(com.google.gson.JsonObject)

Example 99 with RequestBuilder

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

the class Discovery method updateEnvironment.

/**
 * Update an environment.
 *
 * Updates an environment. The environment's `name` and `description` parameters can be changed. You must specify a
 * `name` for the environment.
 *
 * @param updateEnvironmentOptions the {@link UpdateEnvironmentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Environment}
 */
public ServiceCall<Environment> updateEnvironment(UpdateEnvironmentOptions updateEnvironmentOptions) {
    Validator.notNull(updateEnvironmentOptions, "updateEnvironmentOptions cannot be null");
    String[] pathSegments = { "v1/environments" };
    String[] pathParameters = { updateEnvironmentOptions.environmentId() };
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (updateEnvironmentOptions.name() != null) {
        contentJson.addProperty("name", updateEnvironmentOptions.name());
    }
    if (updateEnvironmentOptions.description() != null) {
        contentJson.addProperty("description", updateEnvironmentOptions.description());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Environment.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment)

Example 100 with RequestBuilder

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

the class Discovery method updateConfiguration.

/**
 * Update a configuration.
 *
 * Replaces an existing configuration. * Completely replaces the original configuration. * The `configuration_id`,
 * `updated`, and `created` fields are accepted in the request, but they are ignored, and an error is not generated.
 * It is also acceptable for users to submit an updated configuration with none of the three properties. * Documents
 * are processed with a snapshot of the configuration as it was at the time the document was submitted to be ingested.
 * This means that already submitted documents will not see any updates made to the configuration.
 *
 * @param updateConfigurationOptions the {@link UpdateConfigurationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Configuration}
 */
public ServiceCall<Configuration> updateConfiguration(UpdateConfigurationOptions updateConfigurationOptions) {
    Validator.notNull(updateConfigurationOptions, "updateConfigurationOptions cannot be null");
    String[] pathSegments = { "v1/environments", "configurations" };
    String[] pathParameters = { updateConfigurationOptions.environmentId(), updateConfigurationOptions.configurationId() };
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (updateConfigurationOptions.name() != null) {
        contentJson.addProperty("name", updateConfigurationOptions.name());
    }
    if (updateConfigurationOptions.description() != null) {
        contentJson.addProperty("description", updateConfigurationOptions.description());
    }
    if (updateConfigurationOptions.conversions() != null) {
        contentJson.add("conversions", GsonSingleton.getGson().toJsonTree(updateConfigurationOptions.conversions()));
    }
    if (updateConfigurationOptions.enrichments() != null) {
        contentJson.add("enrichments", GsonSingleton.getGson().toJsonTree(updateConfigurationOptions.enrichments()));
    }
    if (updateConfigurationOptions.normalizations() != null) {
        contentJson.add("normalizations", GsonSingleton.getGson().toJsonTree(updateConfigurationOptions.normalizations()));
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Configuration.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) JsonObject(com.google.gson.JsonObject)

Aggregations

RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)206 JsonObject (com.google.gson.JsonObject)60 MultipartBody (okhttp3.MultipartBody)10 RequestBody (okhttp3.RequestBody)10 Counterexample (com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample)3 DialogNode (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode)3 Example (com.ibm.watson.developer_cloud.assistant.v1.model.Example)3 Synonym (com.ibm.watson.developer_cloud.assistant.v1.model.Synonym)3 Counterexample (com.ibm.watson.developer_cloud.conversation.v1.model.Counterexample)3 DialogNode (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)3 Example (com.ibm.watson.developer_cloud.conversation.v1.model.Example)3 Synonym (com.ibm.watson.developer_cloud.conversation.v1.model.Synonym)3 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)3 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)3 Environment (com.ibm.watson.developer_cloud.discovery.v1.model.Environment)3 Entity (com.ibm.watson.developer_cloud.assistant.v1.model.Entity)2 Intent (com.ibm.watson.developer_cloud.assistant.v1.model.Intent)2 LogCollection (com.ibm.watson.developer_cloud.assistant.v1.model.LogCollection)2 Value (com.ibm.watson.developer_cloud.assistant.v1.model.Value)2 Workspace (com.ibm.watson.developer_cloud.assistant.v1.model.Workspace)2