Amazon Textract Textract를 사용하여 문서 분석AWSSDK - Amazon Textract

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon Textract Textract를 사용하여 문서 분석AWSSDK

다음 코드 예제에서는 Amazon Textract Textract를 사용하여 문서를 분석하는 방법을 보여줍니다.

Java
SDK for Java 2.x

public static void analyzeDoc(TextractClient textractClient, String sourceDoc) { try { InputStream sourceStream = new FileInputStream(new File(sourceDoc)); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); // 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(); System.out.println("The block type is " +block.blockType().toString()); } } catch (TextractException | FileNotFoundException e) { System.err.println(e.getMessage()); System.exit(1); } }
  • GitHub에서 지침과 추가 코드를 확인해 보세요.

  • API 자세한 내용은 단원을 참조하십시오.AnalyzeDocument에서AWS SDK for Java 2.xAPI 참조.

Python
SDK for Python(Boto3)

class TextractWrapper: """Encapsulates Textract functions.""" def __init__(self, textract_client, s3_resource, sqs_resource): """ :param textract_client: A Boto3 Textract client. :param s3_resource: A Boto3 Amazon S3 resource. :param sqs_resource: A Boto3 Amazon SQS resource. """ self.textract_client = textract_client self.s3_resource = s3_resource self.sqs_resource = sqs_resource def analyze_file( self, feature_types, *, document_file_name=None, document_bytes=None): """ Detects text and additional elements, such as forms or tables, in a local image file or from in-memory byte data. The image must be in PNG or JPG format. :param feature_types: The types of additional document features to detect. :param document_file_name: The name of a document image file. :param document_bytes: In-memory byte data of a document image. :return: The response from Amazon Textract, including a list of blocks that describe elements detected in the image. """ if document_file_name is not None: with open(document_file_name, 'rb') as document_file: document_bytes = document_file.read() try: response = self.textract_client.analyze_document( Document={'Bytes': document_bytes}, FeatureTypes=feature_types) logger.info( "Detected %s blocks.", len(response['Blocks'])) except ClientError: logger.exception("Couldn't detect text.") raise else: return response
  • GitHub에서 지침과 추가 코드를 확인해 보세요.

  • API 자세한 내용은 단원을 참조하십시오.AnalyzeDocument에서AWSPython용 API 참조 SDK (Boto3).

의 전체 목록은 단원을 참조하십시오.AWSSDK 개발자 가이드 및 코드 예제는 다음을 참조하십시오.와 함께 Amazon Textract 추출을 사용하여AWSSDK. 이 항목에는 시작에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.