use of com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorIT method testReadme.
/**
* Test README.
*/
@Test
public void testReadme() throws InterruptedException, IOException {
// LanguageTranslator service = new LanguageTranslator();
// service.setUsernameAndPassword("<username>", "<password>");
TranslateOptions translateOptions = new TranslateOptions.Builder().addText("hello").source(Language.ENGLISH).target(Language.SPANISH).build();
TranslationResult translationResult = service.translate(translateOptions).execute();
System.out.println(translationResult);
}
use of com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorIT method testTranslateMultiple.
/**
* Test translate multiple.
*/
@Test
public void testTranslateMultiple() {
TranslateOptions options = new TranslateOptions.Builder(texts).modelId(ENGLISH_TO_SPANISH).build();
TranslationResult results = service.translate(options).execute();
assertEquals(2, results.getTranslations().size());
assertEquals(translations.get(texts.get(0)), results.getTranslations().get(0).getTranslation());
assertEquals(translations.get(texts.get(1)), results.getTranslations().get(1).getTranslation());
TranslateOptions.Builder builder = new TranslateOptions.Builder();
builder.source(Language.ENGLISH).target(Language.SPANISH);
for (String text : texts) {
builder.addText(text);
}
results = service.translate(builder.build()).execute();
assertEquals(2, results.getTranslations().size());
assertEquals(translations.get(texts.get(0)), results.getTranslations().get(0).getTranslation());
assertEquals(translations.get(texts.get(1)), results.getTranslations().get(1).getTranslation());
}
use of com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorIT method testTranslate.
/**
* Test translate.
*/
@Test
public void testTranslate() {
for (String text : texts) {
TranslateOptions options = new TranslateOptions.Builder().addText(text).modelId(ENGLISH_TO_SPANISH).build();
testTranslationResult(text, translations.get(text), service.translate(options).execute());
TranslateOptions options1 = new TranslateOptions.Builder().addText(text).source(Language.ENGLISH).target(Language.SPANISH).build();
testTranslationResult(text, translations.get(text), service.translate(options1).execute());
}
}
use of com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorTest method testTranslateOptions.
/**
* Test translate options.
*/
@Test
public void testTranslateOptions() {
final String text = "Hello, Watson!";
TranslateOptions options1 = new TranslateOptions.Builder().addText(text).modelId(modelId).build();
TranslateOptions.Builder builder = options1.newBuilder();
TranslateOptions options2 = builder.text(texts).build();
assertEquals(options2.text(), texts);
assertEquals(options2.modelId(), modelId);
}
use of com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorTest method testTranslateWithNull.
/**
* Test translate with null.
*/
@Test(expected = IllegalArgumentException.class)
public void testTranslateWithNull() {
TranslateOptions translateOptions = new TranslateOptions.Builder().build();
service.translate(translateOptions).execute();
}
Aggregations