Search in sources :

Example 1 with TranslationModel

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

the class LanguageTranslatorIT method testGetModel.

/**
 * Test Get model by id.
 */
@Test
public void testGetModel() {
    GetModelOptions getOptions = new GetModelOptions.Builder(ENGLISH_TO_SPANISH).build();
    final TranslationModel model = service.getModel(getOptions).execute();
    assertNotNull(model);
}
Also used : TranslationModel(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel) GetModelOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.GetModelOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 2 with TranslationModel

use of com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel 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 3 with TranslationModel

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

the class LanguageTranslatorIT method testCreateAndDeleteModel.

/**
 * Test create and delete model.
 */
@Test
public void testCreateAndDeleteModel() throws IOException {
    String modelName = "integration-test";
    String baseModelId = "en-es";
    InputStream glossary = new FileInputStream(new File(RESOURCE + "glossary.tmx"));
    CreateModelOptions options = new CreateModelOptions.Builder().name(modelName).baseModelId(baseModelId).forcedGlossary(glossary).forcedGlossaryFilename("test_glossary").build();
    TranslationModel model = null;
    try {
        model = service.createModel(options).execute();
        Thread.sleep(3000);
        assertNotNull(model);
        assertTrue(model.getModelId() != null && model.getModelId().length() > 0);
        assertEquals(model.getName(), modelName);
        assertEquals(model.getBaseModelId(), baseModelId);
        assertEquals(model.isCustomizable(), false);
        assertEquals(model.isDefaultModel(), false);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        if (model != null) {
            DeleteModelOptions deleteOptions = new DeleteModelOptions.Builder(model.getModelId()).build();
            service.deleteModel(deleteOptions).execute();
        }
    }
}
Also used : TranslationModel(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DeleteModelOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.DeleteModelOptions) CreateModelOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.CreateModelOptions) File(java.io.File) FileInputStream(java.io.FileInputStream) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 4 with TranslationModel

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

the class LanguageTranslatorIT method testDeleteAllModels.

/**
 * Test delete all models.
 */
@Test
@Ignore
public void testDeleteAllModels() {
    List<TranslationModel> models = service.listModels(null).execute().getModels();
    for (TranslationModel translationModel : models) {
        DeleteModelOptions options = new DeleteModelOptions.Builder(translationModel.getModelId()).build();
        service.deleteModel(options).execute();
    }
}
Also used : TranslationModel(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel) DeleteModelOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.DeleteModelOptions) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 5 with TranslationModel

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

the class LanguageTranslatorTest method testGetModel.

/**
 * Test Get Model.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testGetModel() throws InterruptedException {
    server.enqueue(jsonResponse(model));
    GetModelOptions getOptions = new GetModelOptions.Builder(model.getModelId()).build();
    final TranslationModel returnedModel = service.getModel(getOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(GET_MODELS_PATH + "/" + model.getModelId(), request.getPath());
    assertEquals(model, returnedModel);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) TranslationModel(com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel) GetModelOptions(com.ibm.watson.developer_cloud.language_translator.v2.model.GetModelOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

TranslationModel (com.ibm.watson.developer_cloud.language_translator.v2.model.TranslationModel)8 Test (org.junit.Test)6 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 DeleteModelOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.DeleteModelOptions)2 GetModelOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.GetModelOptions)2 ListModelsOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.ListModelsOptions)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 CreateModelOptions (com.ibm.watson.developer_cloud.language_translator.v2.model.CreateModelOptions)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 MultipartBody (okhttp3.MultipartBody)1 RequestBody (okhttp3.RequestBody)1 Ignore (org.junit.Ignore)1