Search in sources :

Example 1 with MetadataResult

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);
}
Also used : AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) MetadataOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.MetadataOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) Author(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Author) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) FileInputStream(java.io.FileInputStream) MetadataResult(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.MetadataResult) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 AnalysisResults (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults)1 AnalyzeOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions)1 Author (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Author)1 Features (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features)1 MetadataOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.MetadataOptions)1 MetadataResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.MetadataResult)1 FileInputStream (java.io.FileInputStream)1 Test (org.junit.Test)1