Search in sources :

Example 26 with ListWordsOptions

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

the class CustomizationsTest method testListWords.

/**
 * Test list words.
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testListWords() throws InterruptedException {
    final List<Word> expected = instantiateWords();
    server.enqueue(jsonResponse(ImmutableMap.of(WORDS, expected)));
    ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(CUSTOMIZATION_ID).build();
    final Words result = service.listWords(listOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(String.format(WORDS_PATH, CUSTOMIZATION_ID), request.getPath());
    assertEquals("GET", request.getMethod());
    assertEquals(expected, result.getWords());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Word(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word) Words(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words) ListWordsOptions(com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 27 with ListWordsOptions

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

the class SpeechToTextIT method testListWordsCustomizationId.

/**
 * Test list words with just a customization ID.
 */
@Test
@Ignore
public void testListWordsCustomizationId() {
    ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(customizationId).build();
    Words result = service.listWords(listOptions).execute().getResult();
    assertNotNull(result);
    assertTrue(!result.getWords().isEmpty());
}
Also used : Words(com.ibm.watson.speech_to_text.v1.model.Words) ListWordsOptions(com.ibm.watson.speech_to_text.v1.model.ListWordsOptions) Ignore(org.junit.Ignore) WatsonServiceTest(com.ibm.watson.common.WatsonServiceTest) Test(org.junit.Test)

Example 28 with ListWordsOptions

use of com.ibm.watson.text_to_speech.v1.model.ListWordsOptions 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)

Aggregations

Test (org.junit.Test)21 ListWordsOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListWordsOptions)11 Words (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Words)11 Ignore (org.junit.Ignore)11 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)10 ListWordsOptions (com.ibm.watson.speech_to_text.v1.model.ListWordsOptions)8 Words (com.ibm.watson.speech_to_text.v1.model.Words)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)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 Words (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words)6 File (java.io.File)6 MockResponse (okhttp3.mockwebserver.MockResponse)6 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)5 JsonObject (com.google.gson.JsonObject)4 JsonParser (com.google.gson.JsonParser)4 AddWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordOptions)3 Words (com.ibm.watson.text_to_speech.v1.model.Words)3 FileInputStream (java.io.FileInputStream)3