Search in sources :

Example 1 with KeywordsResult

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

the class NaturalLanguageUnderstandingIT method analyzeTextForKeywordsIsSuccessful.

/**
 * Analyze input text for keywords.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextForKeywordsIsSuccessful() throws Exception {
    KeywordsOptions keywords = new KeywordsOptions.Builder().sentiment(true).build();
    Features features = new Features.Builder().keywords(keywords).build();
    AnalyzeOptions parameters = new AnalyzeOptions.Builder().text(text).features(features).returnAnalyzedText(true).build();
    AnalysisResults results = service.analyze(parameters).execute();
    assertNotNull(results);
    assertEquals(results.getAnalyzedText(), text);
    assertNotNull(results.getKeywords());
    for (KeywordsResult result : results.getKeywords()) {
        assertNotNull(result.getRelevance());
        assertNotNull(result.getText());
        assertNotNull(result.getSentiment());
    }
}
Also used : AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) KeywordsOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.KeywordsOptions) KeywordsResult(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.KeywordsResult) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 AnalysisResults (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults)1 AnalyzeOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions)1 Features (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features)1 KeywordsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.KeywordsOptions)1 KeywordsResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.KeywordsResult)1 Test (org.junit.Test)1