Search code examples
amazon-textract

Amazon Textract - How to extract key-value pair


I am using AmazonTextract .NET SDK to extract texts from images. Its returning list of blocks as part of the response. I need to extract key-value pair out of extracted texts. I guess we need to iterate through the list of block, check for KEY_VALUE_SET

Is my understanding right? Can someone give me a piece of code which would give me key value pair after text extraction.

My sample code:

    var DocRequest = new AnalyzeDocumentRequest()
    {
       Document = MyDocument,
       FeatureTypes = new List<string> { Amazon.Textract.FeatureType.FORMS, Amazon.Textract.FeatureType.TABLES }
    };
    var response = client.AnalyzeDocumentAsync(DocRequest);

Solution

  • AWS provides a sample python code for key value mapping in their documentation. It is not terribly complicated. You can try to understand the logic behind the python code and then implement it in your .NET project.

    Here's the mapping code: https://docs.aws.amazon.com/textract/latest/dg/examples-extract-kvp.html