Search in sources :

Example 1 with EntitiesResult

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

the class NaturalLanguageUnderstandingIT method analyzeHtmlForDisambiguationIsSuccessful.

/**
 * Analyze html for disambiguation.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeHtmlForDisambiguationIsSuccessful() throws Exception {
    EntitiesOptions entities = new EntitiesOptions.Builder().sentiment(true).limit(1).build();
    Features features = new Features.Builder().entities(entities).build();
    AnalyzeOptions parameters = new AnalyzeOptions.Builder().url("www.cnn.com").features(features).build();
    AnalysisResults results = service.analyze(parameters).execute();
    assertNotNull(results);
    assertEquals(results.getLanguage(), "en");
    assertNotNull(results.getEntities());
    assertTrue(results.getEntities().size() == 1);
    for (EntitiesResult result : results.getEntities()) {
        assertNotNull(result.getDisambiguation());
        assertEquals(result.getDisambiguation().getName(), "CNN");
        assertEquals(result.getDisambiguation().getDbpediaResource(), "http://dbpedia.org/resource/CNN");
        assertNotNull(result.getDisambiguation().getSubtype());
        assertTrue(result.getDisambiguation().getSubtype().size() > 0);
    }
}
Also used : EntitiesResult(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesResult) 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) EntitiesOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 2 with EntitiesResult

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

the class NaturalLanguageUnderstandingIT method analyzeTextForEntitiesIsSuccessful.

/**
 * Analyze input text for entities.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextForEntitiesIsSuccessful() throws Exception {
    String text = "In 2009, Elliot Turner launched AlchemyAPI to process the written word, with all of its quirks " + "and nuances, and got immediate traction.";
    EntitiesOptions entities = new EntitiesOptions.Builder().limit(2).sentiment(true).build();
    Features features = new Features.Builder().entities(entities).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.getEntities());
    assertTrue(results.getEntities().size() == 2);
    for (EntitiesResult result : results.getEntities()) {
        assertNotNull(result.getCount());
        assertNotNull(result.getRelevance());
        assertNotNull(result.getText());
        assertNotNull(result.getType());
        assertNotNull(result.getSentiment());
    }
}
Also used : EntitiesResult(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesResult) 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) EntitiesOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesOptions) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 AnalysisResults (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults)2 AnalyzeOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions)2 EntitiesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesOptions)2 EntitiesResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesResult)2 Features (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features)2 Test (org.junit.Test)2