Search in sources :

Example 16 with Features

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 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)

Example 17 with Features

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 analyzeTextWithCharacterLimitIsSuccessful.

/**
 * Analyze text while setting a character limit on the analyzed passage.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextWithCharacterLimitIsSuccessful() throws Exception {
    String text = "But I believe this thinking is wrong. I believe the road of true democracy remains the better path." + " I believe that in the 21st century, economies can only grow to a certain point until they need to open up" + " -- because entrepreneurs need to access information in order to invent; young people need a global" + " education in order to thrive; independent media needs to check the abuses of power.";
    Long characterLimit = 10L;
    Features features = new Features.Builder().categories(new CategoriesOptions()).build();
    AnalyzeOptions parameters = new AnalyzeOptions.Builder().text(text).features(features).returnAnalyzedText(true).limitTextCharacters(characterLimit).build();
    AnalysisResults results = service.analyze(parameters).execute();
    assertNotNull(results);
    assertNotNull(results.getAnalyzedText());
    assertTrue(results.getAnalyzedText().length() == characterLimit);
}
Also used : CategoriesOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.CategoriesOptions) AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 18 with Features

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 analyzeTextForKeywordsIsSuccessful.

/**
 * Analyze input text for keywords.
 *
 * @throws Exception the exception
 */
@Test
public void analyzeTextForKeywordsIsSuccessful() throws Exception {
    KeywordsOptions keywords = new KeywordsOptions.Builder().sentiment(true).build();
    Features features = new Features.Builder().keywords(keywords).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.getKeywords());
    for (KeywordsResult result : results.getKeywords()) {
        assertNotNull(result.getRelevance());
        assertNotNull(result.getText());
        assertNotNull(result.getSentiment());
    }
}
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) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) KeywordsOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.KeywordsOptions) KeywordsResult(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.KeywordsResult) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest) Test(org.junit.Test)

Example 19 with Features

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

the class NaturalLanguageUnderstandingTest method testAnalyzeNullParams.

/**
 * Test analyze with null parameters. Test different constructor
 *
 * @throws InterruptedException the interrupted exception
 */
@Test
public void testAnalyzeNullParams() throws InterruptedException {
    NaturalLanguageUnderstanding service1 = new NaturalLanguageUnderstanding("2017-02-27", "username", "password");
    service1.setApiKey("");
    service1.setEndPoint(getMockWebServerUrl());
    server.enqueue(jsonResponse(analyzeResults));
    Features features = new Features.Builder().concepts(null).categories(null).emotion(null).entities(null).keywords(null).metadata(null).relations(null).semanticRoles(null).sentiment(null).build();
    AnalyzeOptions.Builder builder = new AnalyzeOptions.Builder().features(features);
    final AnalysisResults response = service1.analyze(builder.build()).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(ANALYZE_PATH, request.getPath());
    assertEquals("POST", request.getMethod());
    assertEquals(analyzeResults, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) AnalyzeOptions(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions) AnalysisResults(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults) Features(com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 20 with Features

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

the class NaturalLanguageUnderstandingTest method testAnalyze.

/**
 * Test analyze.
 *
 * @throws InterruptedException the interrupted exception
 * @throws FileNotFoundException
 */
@Test
public void testAnalyze() throws InterruptedException, FileNotFoundException {
    String testHtmlFileName = RESOURCE + "testArticle.html";
    String html = getStringFromInputStream(new FileInputStream(testHtmlFileName));
    ConceptsOptions concepts = new ConceptsOptions.Builder().limit(5).build();
    assertEquals(concepts.limit(), 5, 0);
    concepts.newBuilder();
    Features features = new Features.Builder().concepts(concepts).build();
    AnalyzeOptions parameters = new AnalyzeOptions.Builder().html(html).features(features).build();
    server.enqueue(jsonResponse(analyzeResults));
    final AnalysisResults response = service.analyze(parameters).execute();
    final RecordedRequest request = server.takeRequest();
    assertEquals(ANALYZE_PATH, request.getPath());
    assertEquals("POST", request.getMethod());
    assertEquals(analyzeResults, response);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) 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) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

AnalysisResults (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalysisResults)19 AnalyzeOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.AnalyzeOptions)19 Features (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.Features)19 Test (org.junit.Test)19 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)16 ConceptsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsOptions)6 FileInputStream (java.io.FileInputStream)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)3 CategoriesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.CategoriesOptions)3 EntitiesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesOptions)3 SentimentOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SentimentOptions)3 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 ConceptsResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.ConceptsResult)2 EmotionOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EmotionOptions)2 EntitiesResult (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.EntitiesResult)2 KeywordsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.KeywordsOptions)2 MetadataOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.MetadataOptions)2 RelationsOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.RelationsOptions)2 SemanticRolesOptions (com.ibm.watson.developer_cloud.natural_language_understanding.v1.model.SemanticRolesOptions)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2