Search in sources :

Example 1 with DetectEntitiesRequest

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

the class DetectEntities method detectAllEntities.

// snippet-start:[comprehend.java2.detect_entities.main]
public static void detectAllEntities(ComprehendClient comClient, String text) {
    try {
        DetectEntitiesRequest detectEntitiesRequest = DetectEntitiesRequest.builder().text(text).languageCode("en").build();
        DetectEntitiesResponse detectEntitiesResult = comClient.detectEntities(detectEntitiesRequest);
        List<Entity> entList = detectEntitiesResult.entities();
        Iterator<Entity> lanIterator = entList.iterator();
        while (lanIterator.hasNext()) {
            Entity entity = lanIterator.next();
            System.out.println("Entity text is " + entity.text());
        }
    } catch (ComprehendException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : ComprehendException(software.amazon.awssdk.services.comprehend.model.ComprehendException) Entity(software.amazon.awssdk.services.comprehend.model.Entity) DetectEntitiesRequest(software.amazon.awssdk.services.comprehend.model.DetectEntitiesRequest) DetectEntitiesResponse(software.amazon.awssdk.services.comprehend.model.DetectEntitiesResponse)

Aggregations

ComprehendException (software.amazon.awssdk.services.comprehend.model.ComprehendException)1 DetectEntitiesRequest (software.amazon.awssdk.services.comprehend.model.DetectEntitiesRequest)1 DetectEntitiesResponse (software.amazon.awssdk.services.comprehend.model.DetectEntitiesResponse)1 Entity (software.amazon.awssdk.services.comprehend.model.Entity)1