use of com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel 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.language_translator.v2.model.TranslationModel in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorTest method testListModels.
/**
* Test Get Models.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testListModels() throws InterruptedException {
server.enqueue(jsonResponse(models));
ListModelsOptions options = new ListModelsOptions.Builder().build();
final List<TranslationModel> modelList = service.listModels(options).execute().getModels();
final RecordedRequest request = server.takeRequest();
assertEquals(GET_MODELS_PATH, request.getPath());
assertEquals(GSON.toJson(models.getModels()), GSON.toJson(modelList));
}
use of com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel in project java-sdk by watson-developer-cloud.
the class LanguageTranslator method getModel.
/**
* Get model details.
*
* Gets information about a translation model, including training status for custom models.
*
* @param getModelOptions the {@link GetModelOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link TranslationModel}
*/
public ServiceCall<TranslationModel> getModel(GetModelOptions getModelOptions) {
Validator.notNull(getModelOptions, "getModelOptions cannot be null");
String[] pathSegments = { "v2/models" };
String[] pathParameters = { getModelOptions.modelId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TranslationModel.class));
}
Aggregations