use of com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguages 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);
}
use of com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguages 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());
}
use of com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguages in project java-sdk by watson-developer-cloud.
the class LanguageTranslatorTest method setUp.
/*
* (non-Javadoc)
* @see com.ibm.watson.developercloud.WatsonServiceTest#setUp()
*/
@Override
@Before
public void setUp() throws Exception {
super.setUp();
service = new LanguageTranslator();
service.setApiKey("");
service.setEndPoint(getMockWebServerUrl());
// fixtures
String jsonString = getStringFromInputStream(new FileInputStream(RESOURCE + "identifiable_languages.json"));
identifiableLanguages = GSON.fromJson(jsonString, TYPE_IDENTIFIED_LANGUAGES);
model = loadFixture(RESOURCE + "model.json", TranslationModel.class);
models = loadFixture(RESOURCE + "models.json", TranslationModels.class);
identifiedLanguages = loadFixture(RESOURCE + "identify_response.json", IdentifiedLanguages.class);
singleTranslation = loadFixture(RESOURCE + "single_translation.json", TranslationResult.class);
multipleTranslations = loadFixture(RESOURCE + "multiple_translations.json", TranslationResult.class);
}
use of com.ibm.watson.developer_cloud.language_translator.v2.model.IdentifiedLanguages in project java-sdk by watson-developer-cloud.
the class LanguageTranslator method identify.
/**
* Identify language.
*
* Identifies the language of the input text.
*
* @param identifyOptions the {@link IdentifyOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link IdentifiedLanguages}
*/
public ServiceCall<IdentifiedLanguages> identify(IdentifyOptions identifyOptions) {
Validator.notNull(identifyOptions, "identifyOptions cannot be null");
String[] pathSegments = { "v2/identify" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.bodyContent(identifyOptions.text(), "text/plain");
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(IdentifiedLanguages.class));
}
Aggregations