Search in sources :

Example 6 with Corpus

use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpus in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testDeleteCorpus.

/**
 * Test delete corpus.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testDeleteCorpus() throws InterruptedException, FileNotFoundException {
    String id = "foo";
    String corpus = "cName";
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
    DeleteCorpusOptions deleteOptions = new DeleteCorpusOptions.Builder().customizationId(id).corpusName(corpus).build();
    service.deleteCorpus(deleteOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("DELETE", request.getMethod());
    assertEquals(String.format(PATH_CORPUS, id, corpus), request.getPath());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) DeleteCorpusOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteCorpusOptions) ByteString(okio.ByteString) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 7 with Corpus

use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpus in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testGetCorpus.

/**
 * Test get corpus.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException the file not found exception
 */
@Test
public void testGetCorpus() throws InterruptedException, FileNotFoundException {
    String id = "foo";
    String corpus = "cName";
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
    GetCorpusOptions getOptions = new GetCorpusOptions.Builder().customizationId(id).corpusName(corpus).build();
    service.getCorpus(getOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("GET", request.getMethod());
    assertEquals(String.format(PATH_CORPUS, id, corpus), request.getPath());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ByteString(okio.ByteString) GetCorpusOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetCorpusOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 8 with Corpus

use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpus in project java-sdk by watson-developer-cloud.

the class SpeechToTextTest method testAddCorpus.

/**
 * Test add corpus.
 *
 * @throws InterruptedException the interrupted exception
 * @throws IOException the IO exception
 */
@Test
public void testAddCorpus() throws InterruptedException, IOException {
    String id = "foo";
    String corpusName = "cName";
    File corpusFile = new File("src/test/resources/speech_to_text/corpus-text.txt");
    String corpusFileText = new String(Files.readAllBytes(Paths.get(corpusFile.toURI())));
    server.enqueue(new MockResponse().addHeader(CONTENT_TYPE, HttpMediaType.APPLICATION_JSON).setBody("{}"));
    AddCorpusOptions addOptions = new AddCorpusOptions.Builder().customizationId(id).corpusName(corpusName).corpusFile(corpusFile).corpusFileContentType(HttpMediaType.TEXT_PLAIN).allowOverwrite(true).build();
    service.addCorpus(addOptions).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals("POST", request.getMethod());
    assertEquals(String.format(PATH_CORPUS, id, corpusName) + "?allow_overwrite=true", request.getPath());
    assertTrue(request.getBody().readUtf8().contains(corpusFileText));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ByteString(okio.ByteString) AddCorpusOptions(com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddCorpusOptions) File(java.io.File) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 9 with Corpus

use of com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpus in project java-sdk by watson-developer-cloud.

the class SpeechToText method getCorpus.

/**
 * Lists information about a corpus for a custom language model.
 *
 * Lists information about a corpus from a custom language model. The information includes the total number of words
 * and out-of-vocabulary (OOV) words, name, and status of the corpus. You must use credentials for the instance of the
 * service that owns a model to list its corpora.
 *
 * @param getCorpusOptions the {@link GetCorpusOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Corpus}
 */
public ServiceCall<Corpus> getCorpus(GetCorpusOptions getCorpusOptions) {
    Validator.notNull(getCorpusOptions, "getCorpusOptions cannot be null");
    String[] pathSegments = { "v1/customizations", "corpora" };
    String[] pathParameters = { getCorpusOptions.customizationId(), getCorpusOptions.corpusName() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Corpus.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Corpus(com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpus)

Aggregations

Test (org.junit.Test)6 AddCorpusOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddCorpusOptions)4 GetCorpusOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.GetCorpusOptions)4 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)3 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)3 Corpora (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpora)3 Corpus (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Corpus)3 File (java.io.File)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 ByteString (okio.ByteString)3 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 AddWordOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.AddWordOptions)2 CreateLanguageModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.CreateLanguageModelOptions)2 DeleteLanguageModelOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteLanguageModelOptions)2 LanguageModel (com.ibm.watson.developer_cloud.speech_to_text.v1.model.LanguageModel)2 ListCorporaOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListCorporaOptions)2 ListWordsOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.ListWordsOptions)2 Words (com.ibm.watson.developer_cloud.speech_to_text.v1.model.Words)2 DeleteCorpusOptions (com.ibm.watson.developer_cloud.speech_to_text.v1.model.DeleteCorpusOptions)1