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