Search in sources :

Example 1 with TextractClient

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

the class DetectDocumentText method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <sourceDoc> \n\n" + "Where:\n" + "    sourceDoc - the path where the document is located (must be an image, for example, C:/AWS/book.png). \n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String sourceDoc = args[0];
    Region region = Region.US_EAST_2;
    TextractClient textractClient = TextractClient.builder().region(region).build();
    detectDocText(textractClient, sourceDoc);
    textractClient.close();
}
Also used : TextractClient(software.amazon.awssdk.services.textract.TextractClient) Region(software.amazon.awssdk.regions.Region)

Example 2 with TextractClient

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

the class StartDocumentAnalysis method main.

public static void main(String[] args) {
    final String usage = "\n" + "Usage:\n" + "    <bucketName> <docName> \n\n" + "Where:\n" + "    bucketName - the name of the Amazon S3 bucket that contains the document. \n\n" + "    docName - the document name (must be an image, for example, book.png). \n";
    if (args.length != 2) {
        System.out.println(usage);
        System.exit(1);
    }
    String bucketName = args[0];
    String docName = args[1];
    Region region = Region.US_WEST_2;
    TextractClient textractClient = TextractClient.builder().region(region).build();
    String jobId = startDocAnalysisS3(textractClient, bucketName, docName);
    System.out.println("Getting results for job " + jobId);
    String status = getJobResults(textractClient, jobId);
    System.out.println("The job status is " + status);
    textractClient.close();
}
Also used : TextractClient(software.amazon.awssdk.services.textract.TextractClient) Region(software.amazon.awssdk.regions.Region)

Example 3 with TextractClient

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

the class AnalyzeDocument method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <sourceDoc> \n\n" + "Where:\n" + "    sourceDoc - the path where the document is located (must be an image, for example, C:/AWS/book.png). \n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String sourceDoc = args[0];
    Region region = Region.US_EAST_2;
    TextractClient textractClient = TextractClient.builder().region(region).build();
    analyzeDoc(textractClient, sourceDoc);
    textractClient.close();
}
Also used : TextractClient(software.amazon.awssdk.services.textract.TextractClient) Region(software.amazon.awssdk.regions.Region)

Example 4 with TextractClient

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

the class DetectDocumentTextS3 method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <bucketName> <docName> \n\n" + "Where:\n" + "    bucketName - The name of the Amazon S3 bucket that contains the document. \n\n" + "    docName - The document name (must be an image, i.e., book.png). \n";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucketName = args[0];
    String docName = args[1];
    Region region = Region.US_WEST_2;
    TextractClient textractClient = TextractClient.builder().region(region).build();
    detectDocTextS3(textractClient, bucketName, docName);
    textractClient.close();
}
Also used : TextractClient(software.amazon.awssdk.services.textract.TextractClient) Region(software.amazon.awssdk.regions.Region)

Example 5 with TextractClient

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

the class TextractService method analyzeDoc.

public String analyzeDoc(byte[] bytes) {
    List myList = new ArrayList<String>();
    try {
        Region region = Region.US_EAST_2;
        TextractClient textractClient = TextractClient.builder().region(region).build();
        SdkBytes sourceBytes = SdkBytes.fromByteArray(bytes);
        // Get the input Document object as bytes
        Document myDoc = Document.builder().bytes(sourceBytes).build();
        List<FeatureType> featureTypes = new ArrayList<FeatureType>();
        featureTypes.add(FeatureType.FORMS);
        featureTypes.add(FeatureType.TABLES);
        AnalyzeDocumentRequest analyzeDocumentRequest = AnalyzeDocumentRequest.builder().featureTypes(featureTypes).document(myDoc).build();
        AnalyzeDocumentResponse analyzeDocument = textractClient.analyzeDocument(analyzeDocumentRequest);
        List<Block> docInfo = analyzeDocument.blocks();
        Iterator<Block> blockIterator = docInfo.iterator();
        while (blockIterator.hasNext()) {
            Block block = blockIterator.next();
            myList.add("The block type is " + block.blockType().toString());
        }
        return convertToString(toXml(myList));
    } catch (TextractException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    return "";
}
Also used : FeatureType(software.amazon.awssdk.services.textract.model.FeatureType) TextractClient(software.amazon.awssdk.services.textract.TextractClient) TextractException(software.amazon.awssdk.services.textract.model.TextractException) ArrayList(java.util.ArrayList) Document(software.amazon.awssdk.services.textract.model.Document) AnalyzeDocumentResponse(software.amazon.awssdk.services.textract.model.AnalyzeDocumentResponse) SdkBytes(software.amazon.awssdk.core.SdkBytes) Region(software.amazon.awssdk.regions.Region) Block(software.amazon.awssdk.services.textract.model.Block) ArrayList(java.util.ArrayList) List(java.util.List) AnalyzeDocumentRequest(software.amazon.awssdk.services.textract.model.AnalyzeDocumentRequest)

Aggregations

Region (software.amazon.awssdk.regions.Region)5 TextractClient (software.amazon.awssdk.services.textract.TextractClient)5 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 AnalyzeDocumentRequest (software.amazon.awssdk.services.textract.model.AnalyzeDocumentRequest)1 AnalyzeDocumentResponse (software.amazon.awssdk.services.textract.model.AnalyzeDocumentResponse)1 Block (software.amazon.awssdk.services.textract.model.Block)1 Document (software.amazon.awssdk.services.textract.model.Document)1 FeatureType (software.amazon.awssdk.services.textract.model.FeatureType)1 TextractException (software.amazon.awssdk.services.textract.model.TextractException)1