Search in sources :

Example 1 with TargetedSentimentResults

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

the class NaturalLanguageUnderstandingIT method analyzeTextForSentimentWithTargetsIsSuccessful.

/**
 * Analyze input text for sentiment with targets.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextForSentimentWithTargetsIsSuccessful() throws Exception {
    SentimentOptions options = new SentimentOptions.Builder().document(true).targets(Arrays.asList("Elliot Turner", "traction")).build();
    Features features = new Features.Builder().sentiment(options).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);
    assertEquals(results.getLanguage(), "en");
    assertNotNull(results.getSentiment());
    assertNotNull(results.getSentiment().getDocument());
    assertNotNull(results.getSentiment().getDocument().getScore());
    assertNotNull(results.getSentiment().getTargets());
    for (TargetedSentimentResults result : results.getSentiment().getTargets()) {
        assertNotNull(result.getText());
        assertNotNull(result.getScore());
    }
}
Also used : SentimentOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SentimentOptions) AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) TargetedSentimentResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.TargetedSentimentResults) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) 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 SentimentOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SentimentOptions)1 TargetedSentimentResults (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.TargetedSentimentResults)1 Test (org.junit.Test)1