use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SemanticRolesResult in project java-sdk by watson-developer-cloud.
the class NaturalLanguageUnderstandingIT method analyzeTextForSemanticRolesIsSuccessful.
/**
* Analyze input text for semantic roles.
*
* @throws Exception the exception
*/
@Test
public void analyzeTextForSemanticRolesIsSuccessful() throws Exception {
SemanticRolesOptions options = new SemanticRolesOptions.Builder().limit(7).keywords(true).entities(true).build();
Features features = new Features.Builder().semanticRoles(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.getSemanticRoles());
for (SemanticRolesResult result : results.getSemanticRoles()) {
assertEquals(result.getSentence(), text);
if (result.getSubject() != null) {
assertNotNull(result.getSubject().getText());
}
if (result.getAction() != null) {
assertNotNull(result.getAction().getText());
}
if (result.getObject() != null) {
assertNotNull(result.getObject().getText());
}
}
}
Aggregations