use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesOptions 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);
}
}
use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesOptions 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());
}
}
use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesOptions 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();
}
Aggregations