我正在使用.Net使用amazontextract提取键值对和表,如何从analysedocumentrequest响应中获得的键值对和表中动态提取数据?下面的代码我将块作为静态值传递。
AmazonTextractClient Atc = new AmazonTextractClient(credentials, config);
Document MyDocument;
using (Image image = Image.FromFile(imagePath))
{
using (MemoryStream m = new MemoryStream())
{
image.Save(m, image.RawFormat);
MyDocument = new Document()
{
Bytes = m
};
}
}
var DocRequest = new AnalyzeDocumentRequest()
{
Document = MyDocument,
FeatureTypes = new List<string> { FeatureType.FORMS, FeatureType.TABLES }
};
var response = Atc.AnalyzeDocument(DocRequest);
var reg = response.Blocks.ElementAt(20);
var result= reg.Relationships.Select(r=> r.Ids).ToList();
for (int i = 0; i < result.Count; i++)
{
foreach(var str in result[i])
{
int red = response.Blocks.Count;
for (int j = 1; j < red; j++)
{
if (response.Blocks[j].Id == str)
{
textValue = textValue + " " + response.Blocks[j].Text;
break;
}
}
}
}