Search in sources :

Example 1 with TranslateOptions

use of com.ibm.watson.language_translator.v3.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);
}
Also used : TranslateOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions) TranslationResult(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationResult) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 2 with TranslateOptions

use of com.ibm.watson.language_translator.v3.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());
}
Also used : TranslateOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions) TranslationResult(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationResult) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 3 with TranslateOptions

use of com.ibm.watson.language_translator.v3.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());
    }
}
Also used : TranslateOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 4 with TranslateOptions

use of com.ibm.watson.language_translator.v3.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);
}
Also used : TranslateOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 5 with TranslateOptions

use of com.ibm.watson.language_translator.v3.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();
}
Also used : TranslateOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

TranslateOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslateOptions)10 Test (org.junit.Test)8 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)5 TranslationResult (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationResult)5 TranslationResult (com.ibm.watson.language_translator.v3.model.TranslationResult)4 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)3 TranslateOptions (com.ibm.watson.language_translator.v3.model.TranslateOptions)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)2 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)2 File (java.io.File)2 InputStream (java.io.InputStream)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 TranslationResult (com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationResult)1 LanguageTranslator (com.ibm.watson.developer_cloud.language_translator.v2.LanguageTranslator)1 SynthesizeOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.SynthesizeOptions)1 LanguageTranslator (com.ibm.watson.language_translator.v3.LanguageTranslator)1 SynthesizeOptions (com.ibm.watson.text_to_speech.v1.model.SynthesizeOptions)1 MockResponse (okhttp3.mockwebserver.MockResponse)1