Search in sources :

Example 1 with AnalysisResults

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

the class NaturalLanguageUnderstandingIT method analyzeTextForSentimentWithoutTargetsIsSuccessful.

/**
 * Analyze input text for sentiment without targets.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextForSentimentWithoutTargetsIsSuccessful() throws Exception {
    SentimentOptions options = new SentimentOptions.Builder().document(true).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());
    assertNull(results.getSentiment().getTargets());
}
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) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 2 with AnalysisResults

use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults 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 3 with AnalysisResults

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

the class NaturalLanguageUnderstandingIT method analyzeHtmlForMetadataIsSuccessful.

/**
 * Analyze html input for metadata.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeHtmlForMetadataIsSuccessful() throws Exception {
    String testHtmlFileName = "src/test/resources/natural_language_understanding/testArticle.html";
    String html = getStringFromInputStream(new FileInputStream(testHtmlFileName));
    String fileTitle = "This 5,000-year-old recipe for beer actually sounds pretty tasty";
    String fileDate = "2016-05-23T20:13:00";
    String fileAuthor = "Annalee Newitz";
    Features features = new Features.Builder().metadata(new MetadataOptions()).build();
    AnalyzeOptions parameters = new AnalyzeOptions.Builder().html(html).features(features).returnAnalyzedText(true).build();
    AnalysisResults results = service.analyze(parameters).execute();
    assertNotNull(results);
    assertEquals(results.getLanguage(), "en");
    assertNotNull(results.getMetadata());
    MetadataResult result = results.getMetadata();
    assertNotNull(result.getTitle());
    assertEquals(result.getTitle(), fileTitle);
    assertNotNull(result.getPublicationDate());
    assertEquals(result.getPublicationDate(), fileDate);
    assertNotNull(result.getAuthors());
    List<Author> authors = result.getAuthors();
    assertEquals(authors.size(), 1);
    assertEquals(authors.get(0).getName(), fileAuthor);
}
Also used : AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) MetadataOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.MetadataOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) Author(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Author) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) FileInputStream(java.io.FileInputStream) MetadataResult(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.MetadataResult) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 4 with AnalysisResults

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

the class NaturalLanguageUnderstandingIT method analyzeTextIsSuccessful.

/**
 * Default test for text input.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextIsSuccessful() throws Exception {
    ConceptsOptions concepts = new ConceptsOptions.Builder().limit(5).build();
    Features features = new Features.Builder().concepts(concepts).build();
    AnalyzeOptions parameters = new AnalyzeOptions.Builder().text(text).features(features).build();
    AnalysisResults results = service.analyze(parameters).execute();
    assertNotNull(results);
}
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) ConceptsOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 5 with AnalysisResults

use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults 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

AnalysisResults (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults)19 AnalyzeOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions)18 Features (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features)18 Test (org.junit.Test)18 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)16 ConceptsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions)6 FileInputStream (java.io.FileInputStream)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 CategoriesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.CategoriesOptions)2 ConceptsResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsResult)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 SentimentOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SentimentOptions)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1 Author (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Author)1 CategoriesResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.CategoriesResult)1 EmotionOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EmotionOptions)1 EmotionScores (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EmotionScores)1