AWS SDK を使用して Amazon Textract ドキュメント分析を開始する - AWS SDK コードサンプル

Doc AWS SDK Examples リポジトリには、他にも SDK の例があります。 AWS GitHub

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK を使用して Amazon Textract ドキュメント分析を開始する

次のコードサンプルは、以下の操作方法を示しています。

  • 非同期分析を開始します。

  • ドキュメント分析を取得します。

SAP ABAP
SDK for SAP ABAP
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

"Create ABAP objects for feature type." "Add TABLES to return information about the tables." "Add FORMS to return detected form data." "To perform both types of analysis, add TABLES and FORMS to FeatureTypes." DATA(lt_featuretypes) = VALUE /aws1/cl_texfeaturetypes_w=>tt_featuretypes( ( NEW /aws1/cl_texfeaturetypes_w( iv_value = 'FORMS' ) ) ( NEW /aws1/cl_texfeaturetypes_w( iv_value = 'TABLES' ) ) ). "Create an ABAP object for the Amazon Simple Storage Service (Amazon S3) object." DATA(lo_s3object) = NEW /aws1/cl_texs3object( iv_bucket = iv_s3bucket iv_name = iv_s3object ). "Create an ABAP object for the document." DATA(lo_documentlocation) = NEW /aws1/cl_texdocumentlocation( io_s3object = lo_s3object ). "Start document analysis." TRY. DATA(lo_start_result) = lo_tex->startdocumentanalysis( io_documentlocation = lo_documentlocation it_featuretypes = lt_featuretypes ). MESSAGE 'Document analysis started.' TYPE 'I'. CATCH /aws1/cx_texaccessdeniedex. MESSAGE 'You do not have permission to perform this action.' TYPE 'E'. CATCH /aws1/cx_texbaddocumentex. MESSAGE 'Amazon Textract is not able to read the document.' TYPE 'E'. CATCH /aws1/cx_texdocumenttoolargeex. MESSAGE 'The document is too large.' TYPE 'E'. CATCH /aws1/cx_texidempotentprmmis00. MESSAGE 'Idempotent parameter mismatch exception.' TYPE 'E'. CATCH /aws1/cx_texinternalservererr. MESSAGE 'Internal server error.' TYPE 'E'. CATCH /aws1/cx_texinvalidkmskeyex. MESSAGE 'AWS KMS key is not valid.' TYPE 'E'. CATCH /aws1/cx_texinvalidparameterex. MESSAGE 'Request has non-valid parameters.' TYPE 'E'. CATCH /aws1/cx_texinvalids3objectex. MESSAGE 'Amazon S3 object is not valid.' TYPE 'E'. CATCH /aws1/cx_texlimitexceededex. MESSAGE 'An Amazon Textract service limit was exceeded.' TYPE 'E'. CATCH /aws1/cx_texprovthruputexcdex. MESSAGE 'Provisioned throughput exceeded limit.' TYPE 'E'. CATCH /aws1/cx_texthrottlingex. MESSAGE 'The request processing exceeded the limit.' TYPE 'E'. CATCH /aws1/cx_texunsupporteddocex. MESSAGE 'The document is not supported.' TYPE 'E'. ENDTRY. "Get job ID from the output." DATA(lv_jobid) = lo_start_result->get_jobid( ). "Wait for job to complete." oo_result = lo_tex->getdocumentanalysis( iv_jobid = lv_jobid ). " oo_result is returned for testing purposes. " WHILE oo_result->get_jobstatus( ) <> 'SUCCEEDED'. IF sy-index = 10. EXIT. "Maximum 300 seconds." ENDIF. WAIT UP TO 30 SECONDS. oo_result = lo_tex->getdocumentanalysis( iv_jobid = lv_jobid ). ENDWHILE. DATA(lt_blocks) = oo_result->get_blocks( ). LOOP AT lt_blocks INTO DATA(lo_block). IF lo_block->get_text( ) = 'INGREDIENTS: POWDERED SUGAR* (CANE SUGAR,'. MESSAGE 'Found text in the doc: ' && lo_block->get_text( ) TYPE 'I'. ENDIF. ENDLOOP.