Search in sources :

Example 1 with DetectKeyPhrasesRequest

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

the class DetectKeyPhrases method detectAllKeyPhrases.

// snippet-start:[comprehend.java2.detect_keyphrases.main]
public static void detectAllKeyPhrases(ComprehendClient comClient, String text) {
    try {
        DetectKeyPhrasesRequest detectKeyPhrasesRequest = DetectKeyPhrasesRequest.builder().text(text).languageCode("en").build();
        DetectKeyPhrasesResponse detectKeyPhrasesResult = comClient.detectKeyPhrases(detectKeyPhrasesRequest);
        List<KeyPhrase> phraseList = detectKeyPhrasesResult.keyPhrases();
        Iterator<KeyPhrase> keyIterator = phraseList.iterator();
        while (keyIterator.hasNext()) {
            KeyPhrase keyPhrase = keyIterator.next();
            System.out.println("Key phrase text is " + keyPhrase.text());
        }
    } catch (ComprehendException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ComprehendException(software.amazon.awssdk.services.comprehend.model.ComprehendException) DetectKeyPhrasesRequest(software.amazon.awssdk.services.comprehend.model.DetectKeyPhrasesRequest) DetectKeyPhrasesResponse(software.amazon.awssdk.services.comprehend.model.DetectKeyPhrasesResponse) KeyPhrase(software.amazon.awssdk.services.comprehend.model.KeyPhrase)

Aggregations

ComprehendException (software.amazon.awssdk.services.comprehend.model.ComprehendException)1 DetectKeyPhrasesRequest (software.amazon.awssdk.services.comprehend.model.DetectKeyPhrasesRequest)1 DetectKeyPhrasesResponse (software.amazon.awssdk.services.comprehend.model.DetectKeyPhrasesResponse)1 KeyPhrase (software.amazon.awssdk.services.comprehend.model.KeyPhrase)1