Search in sources :

Example 11 with AnalyzeOptions

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

the class NaturalLanguageUnderstandingIT method analyzeTextForCategoriesIsSuccessful.

/**
 * Analyze input text for categories.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextForCategoriesIsSuccessful() throws Exception {
    Features features = new Features.Builder().categories(new CategoriesOptions()).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.getCategories());
    for (CategoriesResult result : results.getCategories()) {
        assertNotNull(result.getLabel());
        assertNotNull(result.getScore());
    }
}
Also used : CategoriesOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.CategoriesOptions) AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) CategoriesResult(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.CategoriesResult) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 12 with AnalyzeOptions

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

the class NaturalLanguageUnderstandingIT method analyzeTextForSentimentWithTargetsIsSuccessful.

/**
 * Analyze input text for sentiment with targets.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextForSentimentWithTargetsIsSuccessful() throws Exception {
    SentimentOptions options = new SentimentOptions.Builder().document(true).targets(Arrays.asList("Elliot Turner", "traction")).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());
    assertNotNull(results.getSentiment().getTargets());
    for (TargetedSentimentResults result : results.getSentiment().getTargets()) {
        assertNotNull(result.getText());
        assertNotNull(result.getScore());
    }
}
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) TargetedSentimentResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.TargetedSentimentResults) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 13 with AnalyzeOptions

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

the class NaturalLanguageUnderstandingIT method analyzeUrlIsSuccessful.

/**
 * Default test for URL input.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeUrlIsSuccessful() throws Exception {
    String url = "http://www.politico.com/story/2016/07/dnc-2016-obama-prepared-remarks-226345";
    ConceptsOptions concepts = new ConceptsOptions.Builder().limit(5).build();
    Features features = new Features.Builder().concepts(concepts).build();
    AnalyzeOptions parameters = new AnalyzeOptions.Builder().url(url).features(features).returnAnalyzedText(true).build();
    AnalysisResults results = service.analyze(parameters).execute();
    assertNotNull(results);
    assertNotNull(results.getAnalyzedText());
}
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 14 with AnalyzeOptions

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

the class NaturalLanguageUnderstandingIT method analyzeTextForRelationsIsSuccessful.

/**
 * Analyze input text for relations.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextForRelationsIsSuccessful() throws Exception {
    Features features = new Features.Builder().relations(new RelationsOptions.Builder().build()).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.getRelations());
}
Also used : AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) RelationsOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.RelationsOptions) 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 15 with AnalyzeOptions

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

the class NaturalLanguageUnderstandingIT method analyzeHtmlIsSuccessful.

/**
 * Default test for HTML input.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeHtmlIsSuccessful() throws Exception {
    String testHtmlFileName = "src/test/resources/natural_language_understanding/testArticle.html";
    String html = getStringFromInputStream(new FileInputStream(testHtmlFileName));
    ConceptsOptions concepts = new ConceptsOptions.Builder().limit(5).build();
    Features features = new Features.Builder().concepts(concepts).build();
    AnalyzeOptions parameters = new AnalyzeOptions.Builder().html(html).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) FileInputStream(java.io.FileInputStream) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

AnalysisResults (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults)18 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 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 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 MetadataOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.MetadataOptions)2 RelationsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.RelationsOptions)2 SemanticRolesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SemanticRolesOptions)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1