Search in sources :

Example 1 with S3Object

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

the class StartDocumentAnalysis method startDocAnalysisS3.

// snippet-start:[textract.java2._start_doc_analysis.main]
public static String startDocAnalysisS3(TextractClient textractClient, String bucketName, String docName) {
    try {
        List<FeatureType> myList = new ArrayList<FeatureType>();
        myList.add(FeatureType.TABLES);
        myList.add(FeatureType.FORMS);
        S3Object s3Object = S3Object.builder().bucket(bucketName).name(docName).build();
        DocumentLocation location = DocumentLocation.builder().s3Object(s3Object).build();
        StartDocumentAnalysisRequest documentAnalysisRequest = StartDocumentAnalysisRequest.builder().documentLocation(location).featureTypes(myList).build();
        StartDocumentAnalysisResponse response = textractClient.startDocumentAnalysis(documentAnalysisRequest);
        // Get the job ID
        String jobId = response.jobId();
        return jobId;
    } catch (TextractException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    return "";
}
Also used : FeatureType(software.amazon.awssdk.services.textract.model.FeatureType) DocumentLocation(software.amazon.awssdk.services.textract.model.DocumentLocation) StartDocumentAnalysisRequest(software.amazon.awssdk.services.textract.model.StartDocumentAnalysisRequest) TextractException(software.amazon.awssdk.services.textract.model.TextractException) ArrayList(java.util.ArrayList) S3Object(software.amazon.awssdk.services.textract.model.S3Object) StartDocumentAnalysisResponse(software.amazon.awssdk.services.textract.model.StartDocumentAnalysisResponse)

Example 2 with S3Object

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

the class DetectDocumentTextS3 method detectDocTextS3.

// snippet-start:[textract.java2._detect_s3_text.main]
public static void detectDocTextS3(TextractClient textractClient, String bucketName, String docName) {
    try {
        S3Object s3Object = S3Object.builder().bucket(bucketName).name(docName).build();
        // Create a Document object and reference the s3Object instance
        Document myDoc = Document.builder().s3Object(s3Object).build();
        // Create a DetectDocumentTextRequest object
        DetectDocumentTextRequest detectDocumentTextRequest = DetectDocumentTextRequest.builder().document(myDoc).build();
        // Invoke the detectDocumentText method
        DetectDocumentTextResponse textResponse = textractClient.detectDocumentText(detectDocumentTextRequest);
        List<Block> docInfo = textResponse.blocks();
        Iterator<Block> blockIterator = docInfo.iterator();
        while (blockIterator.hasNext()) {
            Block block = blockIterator.next();
            System.out.println("The block type is " + block.blockType().toString());
        }
        DocumentMetadata documentMetadata = textResponse.documentMetadata();
        System.out.println("The number of pages in the document is " + documentMetadata.pages());
    } catch (TextractException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : DetectDocumentTextResponse(software.amazon.awssdk.services.textract.model.DetectDocumentTextResponse) DocumentMetadata(software.amazon.awssdk.services.textract.model.DocumentMetadata) TextractException(software.amazon.awssdk.services.textract.model.TextractException) Block(software.amazon.awssdk.services.textract.model.Block) S3Object(software.amazon.awssdk.services.textract.model.S3Object) Document(software.amazon.awssdk.services.textract.model.Document) DetectDocumentTextRequest(software.amazon.awssdk.services.textract.model.DetectDocumentTextRequest)

Aggregations

S3Object (software.amazon.awssdk.services.textract.model.S3Object)2 TextractException (software.amazon.awssdk.services.textract.model.TextractException)2 ArrayList (java.util.ArrayList)1 Block (software.amazon.awssdk.services.textract.model.Block)1 DetectDocumentTextRequest (software.amazon.awssdk.services.textract.model.DetectDocumentTextRequest)1 DetectDocumentTextResponse (software.amazon.awssdk.services.textract.model.DetectDocumentTextResponse)1 Document (software.amazon.awssdk.services.textract.model.Document)1 DocumentLocation (software.amazon.awssdk.services.textract.model.DocumentLocation)1 DocumentMetadata (software.amazon.awssdk.services.textract.model.DocumentMetadata)1 FeatureType (software.amazon.awssdk.services.textract.model.FeatureType)1 StartDocumentAnalysisRequest (software.amazon.awssdk.services.textract.model.StartDocumentAnalysisRequest)1 StartDocumentAnalysisResponse (software.amazon.awssdk.services.textract.model.StartDocumentAnalysisResponse)1