我们可以使用这段代码,循环遍历由 textract 的 GetDocumentTextAnalysis() 返回的块中的关系,并获取与其链接的所有子节点。
var relationships = block.Relationships;
if(relationships != null && relationships.Count > 0) {
relationships.ForEach(r => {
if(r.Type == "CHILD") {
r.Ids.ForEach(id => {
var cell = new Cell(blocks.Find(b => b.Id == id), blocks);
if(cell.RowIndex > ri) {
this.Rows.Add(row);
row = new Row();
ri = cell.RowIndex;
}
row.Cells.Add(cell);
});
if(row != null && row.Cells.Count > 0)
this.Rows.Add(row);
}
});
}
供参考 - 请参阅底部的链接以获取代码:-
https://github.com/aws-samples/amazon-textract-code-samples/blob/master/src-csharp/TextractExtensions/Table.cs