Search in sources :

Example 1 with AnalyzeOptions

use of com.ibm.watson.visual_recognition.v4.model.AnalyzeOptions 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 AnalyzeOptions

use of com.ibm.watson.visual_recognition.v4.model.AnalyzeOptions 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 AnalyzeOptions

use of com.ibm.watson.visual_recognition.v4.model.AnalyzeOptions 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 AnalyzeOptions

use of com.ibm.watson.visual_recognition.v4.model.AnalyzeOptions 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 AnalyzeOptions

use of com.ibm.watson.visual_recognition.v4.model.AnalyzeOptions 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

Test (org.junit.Test)20 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 AnalysisResults (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults)17 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)16 ConceptsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions)6 AnalyzeResponse (com.ibm.watson.visual_recognition.v4.model.AnalyzeResponse)4 FileInputStream (java.io.FileInputStream)4 CategoriesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.CategoriesOptions)3 EntitiesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesOptions)3 SentimentOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SentimentOptions)3 AnalyzeOptions (com.ibm.watson.visual_recognition.v4.model.AnalyzeOptions)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 FileWithMetadata (com.ibm.cloud.sdk.core.service.model.FileWithMetadata)2 WatsonServiceTest (com.ibm.watson.common.WatsonServiceTest)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 ConceptsResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsResult)2 EmotionOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EmotionOptions)2 EntitiesResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesResult)2 KeywordsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.KeywordsOptions)2