Search in sources :

Example 1 with SemanticRolesResult

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());
        }
    }
}
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) SemanticRolesOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SemanticRolesOptions) SemanticRolesResult(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SemanticRolesResult) 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 SemanticRolesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SemanticRolesOptions)1 SemanticRolesResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SemanticRolesResult)1 Test (org.junit.Test)1