Search in sources :

Example 11 with LanguageModel

use of com.ibm.watson.speech_to_text.v1.model.LanguageModel in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testGetLanguageModelWOptions.

// Test the getLanguageModel operation with a valid options model parameter
@Test
public void testGetLanguageModelWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"customization_id\": \"customizationId\", \"created\": \"created\", \"updated\": \"updated\", \"language\": \"language\", \"dialect\": \"dialect\", \"versions\": [\"versions\"], \"owner\": \"owner\", \"name\": \"name\", \"description\": \"description\", \"base_model_name\": \"baseModelName\", \"status\": \"pending\", \"progress\": 8, \"error\": \"error\", \"warnings\": \"warnings\"}";
    String getLanguageModelPath = "/v1/customizations/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetLanguageModelOptions model
    GetLanguageModelOptions getLanguageModelOptionsModel = new GetLanguageModelOptions.Builder().customizationId("testString").build();
    // Invoke getLanguageModel() with a valid options model and verify the result
    Response<LanguageModel> response = speechToTextService.getLanguageModel(getLanguageModelOptionsModel).execute();
    assertNotNull(response);
    LanguageModel responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getLanguageModelPath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetLanguageModelOptions(com.ibm.watson.speech_to_text.v1.model.GetLanguageModelOptions) LanguageModel(com.ibm.watson.speech_to_text.v1.model.LanguageModel) Test(org.testng.annotations.Test)

Example 12 with LanguageModel

use of com.ibm.watson.speech_to_text.v1.model.LanguageModel in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testCreateLanguageModelWOptions.

// Test the createLanguageModel operation with a valid options model parameter
@Test
public void testCreateLanguageModelWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"customization_id\": \"customizationId\", \"created\": \"created\", \"updated\": \"updated\", \"language\": \"language\", \"dialect\": \"dialect\", \"versions\": [\"versions\"], \"owner\": \"owner\", \"name\": \"name\", \"description\": \"description\", \"base_model_name\": \"baseModelName\", \"status\": \"pending\", \"progress\": 8, \"error\": \"error\", \"warnings\": \"warnings\"}";
    String createLanguageModelPath = "/v1/customizations";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
    // Construct an instance of the CreateLanguageModelOptions model
    CreateLanguageModelOptions createLanguageModelOptionsModel = new CreateLanguageModelOptions.Builder().name("testString").baseModelName("ar-MS_Telephony").dialect("testString").description("testString").build();
    // Invoke createLanguageModel() with a valid options model and verify the result
    Response<LanguageModel> response = speechToTextService.createLanguageModel(createLanguageModelOptionsModel).execute();
    assertNotNull(response);
    LanguageModel responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, createLanguageModelPath);
    // Verify that there is no query string
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CreateLanguageModelOptions(com.ibm.watson.speech_to_text.v1.model.CreateLanguageModelOptions) LanguageModel(com.ibm.watson.speech_to_text.v1.model.LanguageModel) Test(org.testng.annotations.Test)

Example 13 with LanguageModel

use of com.ibm.watson.speech_to_text.v1.model.LanguageModel in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testCreateLanguageModel.

/**
 * Test create language model.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testCreateLanguageModel() throws InterruptedException, FileNotFoundException {
    LanguageModel model = loadFixture("src/test/resources/speech_to_text/customization.json", LanguageModel.class);
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(GSON.toJson(model)));
    CreateLanguageModelOptions createOptions = new CreateLanguageModelOptions.Builder().name(model.getName()).baseModelName("en-GB_BroadbandModel").description(model.getDescription()).build();
    LanguageModel result = service.createLanguageModel(createOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("POST", request.getMethod());
    assertEquals(PATH_CUSTOMIZATIONS, request.getPath());
    assertEquals(result.toString(), model.toString());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CreateLanguageModelOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateLanguageModelOptions) LanguageModel(com.ibm.watson.developer_cloud.speech_to_text.v1.model.LanguageModel) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 14 with LanguageModel

use of com.ibm.watson.speech_to_text.v1.model.LanguageModel in project java-sdk by watson-developer-cloud.

the class SpeechToTextIT method isCustomizationReady.

private boolean isCustomizationReady(String customizationId) {
    GetLanguageModelOptions getLanguageModelOptions = new GetLanguageModelOptions.Builder().customizationId(customizationId).build();
    LanguageModel model = service.getLanguageModel(getLanguageModelOptions).execute().getResult();
    return model.getStatus().equals(LanguageModel.Status.READY) || model.getStatus().equals(LanguageModel.Status.AVAILABLE);
}
Also used : GetLanguageModelOptions(com.ibm.watson.speech_to_text.v1.model.GetLanguageModelOptions) LanguageModel(com.ibm.watson.speech_to_text.v1.model.LanguageModel)

Aggregations

LanguageModel (com.ibm.watson.speech_to_text.v1.model.LanguageModel)7 LanguageModel (com.ibm.watson.developer_cloud.speech_to_text.v1.model.LanguageModel)6 File (java.io.File)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 Test (org.junit.Test)4 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 CreateLanguageModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateLanguageModelOptions)3 CreateLanguageModelOptions (com.ibm.watson.speech_to_text.v1.model.CreateLanguageModelOptions)3 GetLanguageModelOptions (com.ibm.watson.speech_to_text.v1.model.GetLanguageModelOptions)3 JsonObject (com.google.gson.JsonObject)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 AddCorpusOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddCorpusOptions)2 AddWordOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddWordOptions)2 Corpora (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpora)2 DeleteLanguageModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteLanguageModelOptions)2 GetCorpusOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetCorpusOptions)2 GetLanguageModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetLanguageModelOptions)2 ListCorporaOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListCorporaOptions)2