Search in sources :

Example 31 with Word

use of com.ibm.watson.text_to_speech.v1.model.Word 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 32 with Word

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

the class CustomizationsTest method instantiateWords.

private static List<Word> instantiateWords() {
    Word word = new Word();
    word.setWord("hodor");
    word.setTranslation("hold the door");
    return ImmutableList.of(word);
}
Also used : Word(com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word)

Example 33 with Word

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

the class SpeechToText method getWord.

/**
 * Lists a custom word from a custom language model.
 *
 * Lists information about a custom word from a custom language model. You must use credentials for the instance of
 * the service that owns a model to query information about its words.
 *
 * @param getWordOptions the {@link GetWordOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Word}
 */
public ServiceCall<Word> getWord(GetWordOptions getWordOptions) {
    Validator.notNull(getWordOptions, "getWordOptions cannot be null");
    String[] pathSegments = { "v1/customizations", "words" };
    String[] pathParameters = { getWordOptions.customizationId(), getWordOptions.wordName() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Word.class));
}
Also used : Word(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder)

Example 34 with Word

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

the class SpeechToTextIT method testGetWord.

/**
 * Test get word.
 */
public void testGetWord() {
    GetWordOptions getOptions = new GetWordOptions.Builder().customizationId(customizationId).wordName("string").build();
    Word result = service.getWord(getOptions).execute().getResult();
    assertNotNull(result);
}
Also used : Word(com.ibm.watson.speech_to_text.v1.model.Word) GetWordOptions(com.ibm.watson.speech_to_text.v1.model.GetWordOptions)

Example 35 with Word

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

the class TextToSpeechTest method testDeleteWordWOptions.

// Test the deleteWord operation with a valid options model parameter
@Test
public void testDeleteWordWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "";
    String deleteWordPath = "/v1/customizations/testString/words/testString";
    server.enqueue(new MockResponse().setResponseCode(204).setBody(mockResponseBody));
    // Construct an instance of the DeleteWordOptions model
    DeleteWordOptions deleteWordOptionsModel = new DeleteWordOptions.Builder().customizationId("testString").word("testString").build();
    // Invoke deleteWord() with a valid options model and verify the result
    Response<Void> response = textToSpeechService.deleteWord(deleteWordOptionsModel).execute();
    assertNotNull(response);
    Void responseObj = response.getResult();
    assertNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "DELETE");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, deleteWordPath);
    // 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) DeleteWordOptions(com.ibm.watson.text_to_speech.v1.model.DeleteWordOptions) Test(org.testng.annotations.Test)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)19 MockResponse (okhttp3.mockwebserver.MockResponse)17 Word (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Word)16 Test (org.junit.Test)15 Test (org.testng.annotations.Test)12 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)7 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)7 AddWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordsOptions)6 ListWordsOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.ListWordsOptions)6 Words (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Words)6 Word (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Word)5 AddWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.AddWordOptions)5 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)4 GetWordOptions (com.ibm.watson.developer_cloud.text_to_speech.v1.model.GetWordOptions)4 Translation (com.ibm.watson.developer_cloud.text_to_speech.v1.model.Translation)4 HashMap (java.util.HashMap)4 CustomWord (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CustomWord)3 Word (com.ibm.watson.speech_to_text.v1.model.Word)3 CustomModel (com.ibm.watson.text_to_speech.v1.model.CustomModel)3 Translation (com.ibm.watson.text_to_speech.v1.model.Translation)3