Search in sources :

Example 1 with CategoriesOptions

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

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

the class NaturalLanguageUnderstandingIT method analyzeTextWithCharacterLimitIsSuccessful.

/**
 * Analyze text while setting a character limit on the analyzed passage.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextWithCharacterLimitIsSuccessful() throws Exception {
    String text = "But I believe this thinking is wrong. I believe the road of true democracy remains the better path." + " I believe that in the 21st century, economies can only grow to a certain point until they need to open up" + " -- because entrepreneurs need to access information in order to invent; young people need a global" + " education in order to thrive; independent media needs to check the abuses of power.";
    Long characterLimit = 10L;
    Features features = new Features.Builder().categories(new CategoriesOptions()).build();
    AnalyzeOptions parameters = new AnalyzeOptions.Builder().text(text).features(features).returnAnalyzedText(true).limitTextCharacters(characterLimit).build();
    AnalysisResults results = service.analyze(parameters).execute();
    assertNotNull(results);
    assertNotNull(results.getAnalyzedText());
    assertTrue(results.getAnalyzedText().length() == characterLimit);
}
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) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 3 with CategoriesOptions

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

the class NaturalLanguageUnderstandingTest method testModelOptions.

/**
 * Test some of the model constructors. pump up the code coverage numbers
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testModelOptions() throws InterruptedException {
    Features features = new Features.Builder().concepts(null).categories(null).emotion(null).entities(null).keywords(null).metadata(null).relations(null).semanticRoles(null).sentiment(null).build();
    // AnalyzeOptions
    AnalyzeOptions analyzeOptions = new AnalyzeOptions.Builder().text("text").html("html").url("url").features(features).clean(true).xpath("xpath").fallbackToRaw(false).returnAnalyzedText(true).language("language").build();
    assertEquals(analyzeOptions.text(), "text");
    assertEquals(analyzeOptions.html(), "html");
    assertEquals(analyzeOptions.url(), "url");
    assertEquals(analyzeOptions.features(), features);
    assertEquals(analyzeOptions.clean(), true);
    assertEquals(analyzeOptions.xpath(), "xpath");
    assertEquals(analyzeOptions.fallbackToRaw(), false);
    assertEquals(analyzeOptions.returnAnalyzedText(), true);
    assertEquals(analyzeOptions.language(), "language");
    analyzeOptions.newBuilder();
    // CategoriesOptions
    CategoriesOptions categoriesOptions = new CategoriesOptions();
    assertNotNull(categoriesOptions);
    // EmotionOptions
    List<String> emotionOptionsTargets = new ArrayList<>(Arrays.asList("target1", "target2"));
    EmotionOptions emotionOptions = new EmotionOptions.Builder().document(true).targets(emotionOptionsTargets).addTargets("target3").build();
    emotionOptionsTargets.add("target3");
    assertEquals(emotionOptions.document(), true);
    assertEquals(emotionOptions.targets(), emotionOptionsTargets);
    emotionOptions.newBuilder();
    // EntitiesOptions
    EntitiesOptions entitiesOptions = new EntitiesOptions.Builder().emotion(true).limit(10).model("model").sentiment(false).mentions(false).build();
    assertEquals(entitiesOptions.emotion(), true);
    assertEquals(entitiesOptions.limit(), 10, 0);
    assertEquals(entitiesOptions.model(), "model");
    assertEquals(entitiesOptions.sentiment(), false);
    assertEquals(entitiesOptions.mentions(), false);
    entitiesOptions.newBuilder();
    // Features
    assertEquals(features.categories(), null);
    assertEquals(features.concepts(), null);
    assertEquals(features.emotion(), null);
    assertEquals(features.entities(), null);
    assertEquals(features.keywords(), null);
    assertEquals(features.metadata(), null);
    assertEquals(features.relations(), null);
    assertEquals(features.semanticRoles(), null);
    assertEquals(features.sentiment(), null);
    features.newBuilder();
    // KeywordsOptions
    KeywordsOptions keywordsOptions = new KeywordsOptions.Builder().emotion(true).limit(10).sentiment(false).build();
    assertEquals(keywordsOptions.emotion(), true);
    assertEquals(keywordsOptions.limit(), 10, 0);
    assertEquals(keywordsOptions.sentiment(), false);
    keywordsOptions.newBuilder();
    // MetadataOptions
    MetadataOptions metadataOptions = new MetadataOptions();
    assertNotNull(metadataOptions);
    // RelationsOptions
    RelationsOptions relationsOptions = new RelationsOptions.Builder().model("model").build();
    assertEquals(relationsOptions.model(), "model");
    relationsOptions.newBuilder();
    // SemanticRolesOptions
    SemanticRolesOptions semanticRolesOptions = new SemanticRolesOptions.Builder().entities(true).keywords(false).limit(10).build();
    assertEquals(semanticRolesOptions.entities(), true);
    assertEquals(semanticRolesOptions.keywords(), false);
    assertEquals(semanticRolesOptions.limit(), 10, 0);
    semanticRolesOptions.newBuilder();
    // SentimentOptions
    List<String> optionsTargets = new ArrayList<>(Arrays.asList("target1", "target2"));
    SentimentOptions sentimentOptions = new SentimentOptions.Builder().document(true).targets(optionsTargets).addTargets("target3").build();
    optionsTargets.add("target3");
    assertEquals(sentimentOptions.document(), true);
    assertEquals(sentimentOptions.targets(), optionsTargets);
    sentimentOptions.newBuilder();
}
Also used : CategoriesOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.CategoriesOptions) SentimentOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SentimentOptions) AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) MetadataOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.MetadataOptions) EmotionOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EmotionOptions) ArrayList(java.util.ArrayList) EntitiesOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesOptions) RelationsOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.RelationsOptions) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) SemanticRolesOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SemanticRolesOptions) KeywordsOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.KeywordsOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

AnalyzeOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions)3 CategoriesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.CategoriesOptions)3 Features (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features)3 Test (org.junit.Test)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 AnalysisResults (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)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 EntitiesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesOptions)1 KeywordsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.KeywordsOptions)1 MetadataOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.MetadataOptions)1 RelationsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.RelationsOptions)1 SemanticRolesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SemanticRolesOptions)1 SentimentOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SentimentOptions)1 ArrayList (java.util.ArrayList)1