Search in sources :

Example 1 with ListModelsOptions

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

the class LanguageTranslatorIT method testListModelsWithOptions.

/**
 * Test List Models with Options.
 */
@Test
public void testListModelsWithOptions() {
    ListModelsOptions options = new ListModelsOptions.Builder().source("en").target("es").defaultModels(false).build();
    final List<TranslationModel> models = service.listModels(options).execute().getModels();
    assertNotNull(models);
    assertFalse(models.isEmpty());
    assertEquals(models.get(0).getSource(), options.source());
    assertEquals(models.get(0).getTarget(), options.target());
}
Also used : ListModelsOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.ListModelsOptions) TranslationModel(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 2 with ListModelsOptions

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

the class LanguageTranslator method listModels.

/**
 * List models.
 *
 * Lists available translation models.
 *
 * @param listModelsOptions the {@link ListModelsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link TranslationModels}
 */
public ServiceCall<TranslationModels> listModels(ListModelsOptions listModelsOptions) {
    String[] pathSegments = { "v2/models" };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    if (listModelsOptions != null) {
        if (listModelsOptions.source() != null) {
            builder.query("source", listModelsOptions.source());
        }
        if (listModelsOptions.target() != null) {
            builder.query("target", listModelsOptions.target());
        }
        if (listModelsOptions.defaultModels() != null) {
            builder.query("default", String.valueOf(listModelsOptions.defaultModels()));
        }
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(TranslationModels.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) TranslationModels(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModels)

Example 3 with ListModelsOptions

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

the class LanguageTranslatorTest method testListModels.

/**
 * Test Get Models.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testListModels() throws InterruptedException {
    server.enqueue(jsonResponse(models));
    ListModelsOptions options = new ListModelsOptions.Builder().build();
    final List<TranslationModel> modelList = service.listModels(options).execute().getModels();
    final RecordedRequest request = server.takeRequest();
    assertEquals(GET_MODELS_PATH, request.getPath());
    assertEquals(GSON.toJson(models.getModels()), GSON.toJson(modelList));
}
Also used : ListModelsOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.ListModelsOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) TranslationModel(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

ListModelsOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.ListModelsOptions)2 TranslationModel (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel)2 Test (org.junit.Test)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 TranslationModels (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModels)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1