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);
}
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);
}
Aggregations