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 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());
}
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 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.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);
}
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 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);
}
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 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());
}
}
Aggregations