use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features in project java-sdk by watson-developer-cloud.
the class NaturalLanguageUnderstandingIT method analyzeHtmlForConceptsIsSuccessful.
/**
* Analyze test HTML for concepts.
*
* @throws Exception the exception
*/
@Test
public void analyzeHtmlForConceptsIsSuccessful() throws Exception {
String testHtmlFileName = "src/test/resources/natural_language_understanding/testArticle.html";
String html = getStringFromInputStream(new FileInputStream(testHtmlFileName));
ConceptsOptions concepts = new ConceptsOptions.Builder().build();
Features features = new Features.Builder().concepts(concepts).build();
AnalyzeOptions parameters = new AnalyzeOptions.Builder().html(html).features(features).returnAnalyzedText(true).build();
AnalysisResults results = service.analyze(parameters).execute();
assertNotNull(results);
assertNotNull(results.getAnalyzedText());
assertNotNull(results.getConcepts());
for (ConceptsResult concept : results.getConcepts()) {
assertNotNull(concept.getText());
assertNotNull(concept.getDbpediaResource());
assertNotNull(concept.getRelevance());
}
}
use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features 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());
}
}
use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features 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());
}
}
use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features 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());
}
use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features 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());
}
Aggregations