Search in sources :

Example 1 with IdentifiedLanguage

use of com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguage in project java-sdk by watson-developer-cloud.

the class LanguageTranslatorTest method testIdentify.

/**
 * Test Identify.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testIdentify() throws InterruptedException {
    server.enqueue(jsonResponse(identifiedLanguages));
    final String text = texts.get(0);
    IdentifyOptions identifyOptions = new IdentifyOptions.Builder(text).build();
    final List<IdentifiedLanguage> identifiedLanguages = service.identify(identifyOptions).execute().getLanguages();
    final RecordedRequest request = server.takeRequest();
    assertEquals(IDENTITY_PATH, request.getPath());
    assertEquals("POST", request.getMethod());
    assertEquals(text, request.getBody().readUtf8());
    assertNotNull(identifiedLanguages);
    assertFalse(identifiedLanguages.isEmpty());
    assertEquals(identifiedLanguages.get(0).getLanguage(), Language.ENGLISH);
    assertEquals(identifiedLanguages.get(0).getConfidence(), 0.877159, 0.05);
    assertEquals(identifiedLanguages.get(1).getLanguage(), Language.AFRIKAANS);
    assertEquals(identifiedLanguages.get(1).getConfidence(), 0.0752636, 0.05);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) IdentifyOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifyOptions) IdentifiedLanguage(com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguage) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with IdentifiedLanguage

use of com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguage in project java-sdk by watson-developer-cloud.

the class LanguageTranslatorIT method testIdentify.

/**
 * Test Identify.
 */
@Test
public void testIdentify() {
    IdentifyOptions options = new IdentifyOptions.Builder(texts.get(0)).build();
    final List<IdentifiedLanguage> identifiedLanguages = service.identify(options).execute().getLanguages();
    assertNotNull(identifiedLanguages);
    assertFalse(identifiedLanguages.isEmpty());
}
Also used : IdentifyOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifyOptions) IdentifiedLanguage(com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguage) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

IdentifiedLanguage (com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguage)2 IdentifyOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifyOptions)2 Test (org.junit.Test)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1