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());
}
}
Aggregations