use of com.ibm.watson.text_to_speech.v1.model.Words in project java-sdk by watson-developer-cloud.
the class SpeechToTextTest method testListWordsSort.
/**
* Test list words with sort order alphabetical.
*
* @throws InterruptedException the interrupted exception
* @throws FileNotFoundException the file not found exception
*/
@Test
public void testListWordsSort() throws InterruptedException, FileNotFoundException {
String id = "foo";
String wordsAsStr = getStringFromInputStream(new FileInputStream("src/test/resources/speech_to_text/words.json"));
JsonObject words = new JsonParser().parse(wordsAsStr).getAsJsonObject();
server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(wordsAsStr));
ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(id).sort(ListWordsOptions.Sort.ALPHABETICAL).build();
Words result = service.listWords(listOptions).execute();
final RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(String.format(PATH_WORDS, id) + "?sort=alphabetical", request.getPath());
assertEquals(words.get("words"), GSON.toJsonTree(result.getWords()));
}
use of com.ibm.watson.text_to_speech.v1.model.Words in project java-sdk by watson-developer-cloud.
the class SpeechToTextTest method testListWordsTypeSort.
/**
* Test list words with word type all and sort order alphabetical.
*
* @throws InterruptedException the interrupted exception
* @throws FileNotFoundException the file not found exception
*/
@Test
public void testListWordsTypeSort() throws InterruptedException, FileNotFoundException {
String id = "foo";
String wordsAsStr = getStringFromInputStream(new FileInputStream("src/test/resources/speech_to_text/words.json"));
JsonObject words = new JsonParser().parse(wordsAsStr).getAsJsonObject();
server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody(wordsAsStr));
ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(id).sort(ListWordsOptions.Sort.ALPHABETICAL).wordType(ListWordsOptions.WordType.ALL).build();
Words result = service.listWords(listOptions).execute();
final RecordedRequest request = server.takeRequest();
assertEquals("GET", request.getMethod());
assertEquals(String.format(PATH_WORDS, id) + "?word_type=all&sort=alphabetical", request.getPath());
assertEquals(words.get("words"), GSON.toJsonTree(result.getWords()));
}
use of com.ibm.watson.text_to_speech.v1.model.Words in project java-sdk by watson-developer-cloud.
the class CustomizationsIT method testAddWords.
/**
* Test add words and list words.
*/
@Test
public void testAddWords() {
model = createVoiceModel();
final List<Word> expected = instantiateWords();
AddWordsOptions addOptions = new AddWordsOptions.Builder().customizationId(model.getCustomizationId()).words(expected).build();
service.addWords(addOptions).execute();
ListWordsOptions listOptions = new ListWordsOptions.Builder().customizationId(model.getCustomizationId()).build();
final Words words = service.listWords(listOptions).execute();
assertEquals(expected.size(), words.getWords().size());
}
use of com.ibm.watson.text_to_speech.v1.model.Words 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());
}
use of com.ibm.watson.text_to_speech.v1.model.Words in project java-sdk by watson-developer-cloud.
the class SpeechToText method listWords.
/**
* Lists all custom words from a custom language model.
*
* Lists information about custom words from a custom language model. You can list all words from the custom model's
* words resource, only custom words that were added or modified by the user, or only out-of-vocabulary (OOV) words
* that were extracted from corpora. You can also indicate the order in which the service is to return words; by
* default, words are listed in ascending alphabetical order. You must use credentials for the instance of the service
* that owns a model to query information about its words.
*
* @param listWordsOptions the {@link ListWordsOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Words}
*/
public ServiceCall<Words> listWords(ListWordsOptions listWordsOptions) {
Validator.notNull(listWordsOptions, "listWordsOptions cannot be null");
String[] pathSegments = { "v1/customizations", "words" };
String[] pathParameters = { listWordsOptions.customizationId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
if (listWordsOptions.wordType() != null) {
builder.query("word_type", listWordsOptions.wordType());
}
if (listWordsOptions.sort() != null) {
builder.query("sort", listWordsOptions.sort());
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Words.class));
}
Aggregations