Search in sources :

Example 1 with DetectSentimentResponse

use of software.amazon.awssdk.services.comprehend.model.DetectSentimentResponse in project aws-doc-sdk-examples by awsdocs.

the class DetectSentiment method detectSentiments.

// snippet-start:[comprehend.java2.detect_sentiment.main]
public static void detectSentiments(ComprehendClient comClient, String text) {
    try {
        DetectSentimentRequest detectSentimentRequest = DetectSentimentRequest.builder().text(text).languageCode("en").build();
        DetectSentimentResponse detectSentimentResult = comClient.detectSentiment(detectSentimentRequest);
        System.out.println("The Neutral value is " + detectSentimentResult.sentimentScore().neutral());
    } catch (ComprehendException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ComprehendException(software.amazon.awssdk.services.comprehend.model.ComprehendException) DetectSentimentRequest(software.amazon.awssdk.services.comprehend.model.DetectSentimentRequest) DetectSentimentResponse(software.amazon.awssdk.services.comprehend.model.DetectSentimentResponse)

Aggregations

ComprehendException (software.amazon.awssdk.services.comprehend.model.ComprehendException)1 DetectSentimentRequest (software.amazon.awssdk.services.comprehend.model.DetectSentimentRequest)1 DetectSentimentResponse (software.amazon.awssdk.services.comprehend.model.DetectSentimentResponse)1