use of com.ibm.watson.speech_to_text.v1.model.Corpus in project java-sdk by watson-developer-cloud.
the class SpeechToTextIT method testCreateLanguageModel.
/**
* Test create language model.
*
* <p>Takes a long time to the point of timing out on Travis sometimes, so we'll just run locally.
*
* @throws InterruptedException the interrupted exception
* @throws FileNotFoundException the file not found exception
*/
@Test
@Ignore
public void testCreateLanguageModel() throws InterruptedException, FileNotFoundException {
CreateLanguageModelOptions createOptions = new CreateLanguageModelOptions.Builder().name("java-sdk-temporary").baseModelName(EN_BROADBAND16K).description("Temporary custom model for testing the Java SDK").build();
LanguageModel myModel = service.createLanguageModel(createOptions).execute().getResult();
String id = myModel.getCustomizationId();
try {
// Add a corpus file to the model
AddCorpusOptions addOptions = new AddCorpusOptions.Builder().customizationId(id).corpusName("corpus-1").corpusFile(new File(String.format(SPEECH_RESOURCE, "corpus1.txt"))).allowOverwrite(false).build();
service.addCorpus(addOptions).execute().getResult();
// Get corpus status
GetCorpusOptions getOptions = new GetCorpusOptions.Builder().customizationId(id).corpusName("corpus-1").build();
for (int x = 0; x < 30 && !service.getCorpus(getOptions).execute().getResult().getStatus().equals(Corpus.Status.ANALYZED); x++) {
Thread.sleep(5000);
}
assertTrue(service.getCorpus(getOptions).execute().getResult().getStatus().equals(Corpus.Status.ANALYZED));
// Add the corpus file to the model again and allow overwrite
AddCorpusOptions addOptionsWithOverwrite = new AddCorpusOptions.Builder().customizationId(id).corpusName("corpus-1").corpusFile(new File(String.format(SPEECH_RESOURCE, "corpus1.txt"))).allowOverwrite(true).build();
service.addCorpus(addOptionsWithOverwrite).execute().getResult();
// Get corpus status
for (int x = 0; x < 30 && !service.getCorpus(getOptions).execute().getResult().getStatus().equals(Corpus.Status.ANALYZED); x++) {
Thread.sleep(5000);
}
assertTrue(service.getCorpus(getOptions).execute().getResult().getStatus().equals(Corpus.Status.ANALYZED));
// Get corpora
ListCorporaOptions listCorporaOptions = new ListCorporaOptions.Builder().customizationId(id).build();
Corpora corpora = service.listCorpora(listCorporaOptions).execute().getResult();
assertNotNull(corpora);
assertTrue(corpora.getCorpora().size() == 1);
// Now add some user words to the custom model
service.addWord(new AddWordOptions.Builder().customizationId(id).wordName("IEEE").word("IEEE").displayAs("IEEE").addSoundsLike("I. triple E.").build()).execute().getResult();
service.addWord(new AddWordOptions.Builder().customizationId(id).wordName("hhonors").word("hhonors").displayAs("IEEE").addSoundsLike("H. honors").addSoundsLike("Hilton honors").build()).execute().getResult();
service.addWord(new AddWordOptions.Builder().customizationId(id).wordName("aaa").word("aaa").displayAs("aaa").addSoundsLike("aaa").addSoundsLike("bbb").build()).execute().getResult();
service.addWord(new AddWordOptions.Builder().customizationId(id).wordName("bbb").word("bbb").addSoundsLike("aaa").addSoundsLike("bbb").build()).execute().getResult();
service.addWord(new AddWordOptions.Builder().customizationId(id).wordName("ccc").word("ccc").displayAs("ccc").build()).execute().getResult();
service.addWord(new AddWordOptions.Builder().customizationId(id).wordName("ddd").word("ddd").build()).execute().getResult();
service.addWord(new AddWordOptions.Builder().customizationId(id).wordName("eee").word("eee").build()).execute().getResult();
// Display all words in the words resource (coming from OOVs from the corpus add
// and the new
// words just added)
ListWordsOptions listWordsOptions = new ListWordsOptions.Builder().customizationId(id).wordType(ListWordsOptions.WordType.ALL).build();
Words words = service.listWords(listWordsOptions).execute().getResult();
assertNotNull(words);
} finally {
DeleteLanguageModelOptions deleteOptions = new DeleteLanguageModelOptions.Builder().customizationId(id).build();
service.deleteLanguageModel(deleteOptions).execute();
}
}
use of com.ibm.watson.speech_to_text.v1.model.Corpus in project java-sdk by watson-developer-cloud.
the class SpeechToTextTest method testGetCorpusWOptions.
// Test the getCorpus operation with a valid options model parameter
@Test
public void testGetCorpusWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"name\": \"name\", \"total_words\": 10, \"out_of_vocabulary_words\": 20, \"status\": \"analyzed\", \"error\": \"error\"}";
String getCorpusPath = "/v1/customizations/testString/corpora/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the GetCorpusOptions model
GetCorpusOptions getCorpusOptionsModel = new GetCorpusOptions.Builder().customizationId("testString").corpusName("testString").build();
// Invoke getCorpus() with a valid options model and verify the result
Response<Corpus> response = speechToTextService.getCorpus(getCorpusOptionsModel).execute();
assertNotNull(response);
Corpus 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, getCorpusPath);
// Verify that there is no query string
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
}
use of com.ibm.watson.speech_to_text.v1.model.Corpus in project java-sdk by watson-developer-cloud.
the class SpeechToTextIT method testGetCorpus.
/**
* Test get corpus.
*/
@Test
@Ignore
public void testGetCorpus() {
GetCorpusOptions getOptions = new GetCorpusOptions.Builder().corpusName("foo3").customizationId(customizationId).build();
Corpus result = service.getCorpus(getOptions).execute();
assertNotNull(result);
}
use of com.ibm.watson.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));
}
use of com.ibm.watson.speech_to_text.v1.model.Corpus in project java-sdk by watson-developer-cloud.
the class SpeechToTextIT method testAddCorpusFail.
/**
* Test add corpus with expected failure.
*/
@Test(expected = IllegalArgumentException.class)
public void testAddCorpusFail() {
AddCorpusOptions addOptions = new AddCorpusOptions.Builder().corpusName("foo3").customizationId(customizationId).build();
service.addCorpus(addOptions).execute().getResult();
}
Aggregations