Search in sources :

Example 46 with Words

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

the class TextToSpeech method listWords.

/**
 * List custom words.
 *
 * <p>Lists all of the words and their translations for the specified custom model. The output
 * shows the translations as they are defined in the model. You must use credentials for the
 * instance of the service that owns a model to list its words.
 *
 * <p>**See also:** [Querying all words from a custom
 * model](https://cloud.ibm.com/docs/text-to-speech?topic=text-to-speech-customWords#cuWordsQueryModel).
 *
 * @param listWordsOptions the {@link ListWordsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Words}
 */
public ServiceCall<Words> listWords(ListWordsOptions listWordsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listWordsOptions, "listWordsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("customization_id", listWordsOptions.customizationId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/customizations/{customization_id}/words", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("text_to_speech", "v1", "listWords");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Words> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Words>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Words(com.ibm.watson.text_to_speech.v1.model.Words)

Example 47 with Words

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

the class TextToSpeechTest method testGetWordWOptions.

// Test the getWord operation with a valid options model parameter
@Test
public void testGetWordWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"translation\": \"translation\", \"part_of_speech\": \"Dosi\"}";
    String getWordPath = "/v1/customizations/testString/words/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetWordOptions model
    GetWordOptions getWordOptionsModel = new GetWordOptions.Builder().customizationId("testString").word("testString").build();
    // Invoke getWord() with a valid options model and verify the result
    Response<Translation> response = textToSpeechService.getWord(getWordOptionsModel).execute();
    assertNotNull(response);
    Translation 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, getWordPath);
    // 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) Translation(com.ibm.watson.text_to_speech.v1.model.Translation) GetWordOptions(com.ibm.watson.text_to_speech.v1.model.GetWordOptions) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.Test)22 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)17 MockResponse (okhttp3.mockwebserver.MockResponse)16 Words (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Words)12 Test (org.testng.annotations.Test)12 ListWordsOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListWordsOptions)11 Ignore (org.junit.Ignore)11 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)10 Words (com.ibm.watson.speech_to_text.v1.model.Words)9 ListWordsOptions (com.ibm.watson.speech_to_text.v1.model.ListWordsOptions)8 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)7 Words (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words)7 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)6 ListWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions)6 Word (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word)6 File (java.io.File)6 JsonObject (com.google.gson.JsonObject)5 JsonParser (com.google.gson.JsonParser)5 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 CustomModel (com.ibm.watson.text_to_speech.v1.model.CustomModel)4