using System.Collections.Generic; using Amazon.Textract.Model; namespace Amazon.Textract.Model { public class TextractDocument { private Dictionary blockMap = new Dictionary(); private List> documentPages = new List>(); public TextractDocument(GetDocumentAnalysisResponse response) { this.Pages = new List(); this.ResponsePages = new List(); this.ResponsePages.Add(response); this.ParseDocumentPagesAndBlockMap(); this.Parse(); } private void ParseDocumentPagesAndBlockMap() { List documentPage = null; this.ResponsePages.ForEach(page => { page.Blocks.ForEach(block => { this.blockMap.Add(block.Id, block); if(block.BlockType == "PAGE") { if (documentPage != null) { this.documentPages.Add(documentPage); } documentPage = new List(); documentPage.Add(block); } else { if (documentPage == null) { documentPage = new List(); } documentPage.Add(block); } }); }); if (documentPage != null) { this.documentPages.Add(documentPage); } } private void Parse() { this.documentPages.ForEach(documentPage => { var page = new Page(documentPage, this.blockMap); this.Pages.Add(page); }); } public Block GetBlockById(string blockId) { return this.blockMap[blockId]; } public List ResponsePages { get; set; } public List Pages { get; set; } public List> PageBlocks { get { return this.documentPages; } } } }