Search in sources :

Example 1 with Detection

use of com.google.cloud.translate.Detection in project google-cloud-java by GoogleCloudPlatform.

the class ITTranslateTest method testDetectLanguageOfText.

@Test
public void testDetectLanguageOfText() {
    Detection detection = TRANSLATE.detect("Hello");
    assertEquals("en", detection.getLanguage());
}
Also used : Detection(com.google.cloud.translate.Detection) Test(org.junit.Test)

Example 2 with Detection

use of com.google.cloud.translate.Detection in project google-cloud-java by GoogleCloudPlatform.

the class ITTranslateTest method testDetectLanguageOfTextList.

@Test
public void testDetectLanguageOfTextList() {
    List<Detection> detections = TRANSLATE.detect(ImmutableList.of("Hello", "Hallo"));
    Detection detection = detections.get(0);
    assertEquals("en", detection.getLanguage());
    detection = detections.get(1);
    assertEquals("de", detection.getLanguage());
}
Also used : Detection(com.google.cloud.translate.Detection) Test(org.junit.Test)

Example 3 with Detection

use of com.google.cloud.translate.Detection in project google-cloud-java by GoogleCloudPlatform.

the class ITTranslateTest method testDetectLanguageOfTexts.

@Test
public void testDetectLanguageOfTexts() {
    List<Detection> detections = TRANSLATE.detect("Hello", "Hallo");
    Detection detection = detections.get(0);
    assertEquals("en", detection.getLanguage());
    detection = detections.get(1);
    assertEquals("de", detection.getLanguage());
}
Also used : Detection(com.google.cloud.translate.Detection) Test(org.junit.Test)

Example 4 with Detection

use of com.google.cloud.translate.Detection in project java-docs-samples by GoogleCloudPlatform.

the class TranslateText method detectLanguage.

/**
 * Detect the language of input text.
 *
 * @param sourceText source text to be detected for language
 * @param out print stream
 */
public static void detectLanguage(String sourceText, PrintStream out) {
    Translate translate = createTranslateService();
    List<Detection> detections = translate.detect(ImmutableList.of(sourceText));
    System.out.println("Language(s) detected:");
    for (Detection detection : detections) {
        out.printf("\t%s\n", detection);
    }
}
Also used : Detection(com.google.cloud.translate.Detection) Translate(com.google.cloud.translate.Translate)

Example 5 with Detection

use of com.google.cloud.translate.Detection in project google-cloud-java by GoogleCloudPlatform.

the class ITTranslateSnippets method testDetectLanguageOfTexts.

@Test
public void testDetectLanguageOfTexts() {
    // SNIPPET translate_detect_language_array
    List<Detection> detections = translate.detect("Hello, World!", "¡Hola Mundo!");
    // SNIPPET translate_detect_language_array
    Detection detection = detections.get(0);
    assertEquals("en", detection.getLanguage());
    detection = detections.get(1);
    assertEquals("es", detection.getLanguage());
}
Also used : Detection(com.google.cloud.translate.Detection) Test(org.junit.Test)

Aggregations

Detection (com.google.cloud.translate.Detection)8 Test (org.junit.Test)6 Translate (com.google.cloud.translate.Translate)2 Translation (com.google.cloud.translate.Translation)1 LinkedList (java.util.LinkedList)1