Search in sources :

Example 1 with ConceptsOptions

use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions 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);
}
Also used : AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) ConceptsOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 2 with ConceptsOptions

use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions in project java-sdk by watson-developer-cloud.

the class NaturalLanguageUnderstandingIT method analyzeTextForConceptsIsSuccessful.

/**
 * Analyze given test input text for concepts.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextForConceptsIsSuccessful() throws Exception {
    String text = "In remote corners of the world, citizens are demanding respect" + " for the dignity of all people no matter their gender, or race, or religion, or disability," + " or sexual orientation, and those who deny others dignity are subject to public reproach." + " An explosion of social media has given ordinary people more ways to express themselves," + " and has raised people's expectations for those of us in power. Indeed, our international" + " order has been so successful that we take it as a given that great powers no longer" + " fight world wars; that the end of the Cold War lifted the shadow of nuclear Armageddon;" + " that the battlefields of Europe have been replaced by peaceful union; that China and India" + " remain on a path of remarkable growth.";
    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).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());
    }
}
Also used : AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) ConceptsOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) ConceptsResult(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsResult) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 3 with ConceptsOptions

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

Example 4 with ConceptsOptions

use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions 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());
}
Also used : AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) ConceptsOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 5 with ConceptsOptions

use of com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions in project java-sdk by watson-developer-cloud.

the class NaturalLanguageUnderstandingIT method analyzeHtmlIsSuccessful.

/**
 * Default test for HTML input.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeHtmlIsSuccessful() throws Exception {
    String testHtmlFileName = "src/test/resources/natural_language_understanding/testArticle.html";
    String html = getStringFromInputStream(new FileInputStream(testHtmlFileName));
    ConceptsOptions concepts = new ConceptsOptions.Builder().limit(5).build();
    Features features = new Features.Builder().concepts(concepts).build();
    AnalyzeOptions parameters = new AnalyzeOptions.Builder().html(html).features(features).build();
    AnalysisResults results = service.analyze(parameters).execute();
    assertNotNull(results);
}
Also used : AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) ConceptsOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) FileInputStream(java.io.FileInputStream) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Aggregations

AnalysisResults (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults)6 AnalyzeOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions)6 ConceptsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions)6 Features (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features)6 Test (org.junit.Test)6 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)5 FileInputStream (java.io.FileInputStream)3 ConceptsResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsResult)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1