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