本节重点介绍您在文档文件 InvokeDataAutomationAsync 上运行 API 操作时收到的不同响应对象。下面我们将分解响应对象的每个部分,然后查看示例文档的完整填充响应。我们将收到的第一部分是 metadata。
"metadata":{
"logical_subdocument_id":"XXXX-XXXX-XXXX-XXXX",
"semantic_modality":"DOCUMENT",
"s3_bucket":"bucket",
"s3_prefix":"prefix"
},
上面的第一部分概述了与文档关联的元数据。除了 S3 信息外,此部分还会告知您为响应选择了哪种模态。
"document":{
"representation":{
"text":"document text",
"html":"document title document content",
"markdown":"# text"
},
"description":"document text",
"summary":"summary text",
"statistics":{
"element_count":5,
"table_count":1,
"figure_count":1,
"word_count":1000,
"line_count":32
}
},
上面的部分提供文档级别粒度的信息。description 和 summary 部分是基于文档生成的字段。representation 部分提供文档中各种格式样式的实际内容。最后,statistics 包含有关文档实际内容的信息,例如有多少语义元素,有多少图、单词、行等。
这是表实体的信息。对于 InvokeDataAutomationAsync (异步)请求,除了位置信息、不同格式的文本、表格和阅读顺序外,它们还专门返回 S3 存储桶中的 csv 信息和 S3 存储桶中表的裁剪图像。CSV 信息显示不同的页眉、页脚和标题。图像将被路由到 InvokeDataAutomationAsync 请求中设置的前缀的 s3 存储桶。对于 InvokeDataAutomation (同步)请求,不支持 S3 存储桶中表的 csv 和裁剪后的图像。
当您处理 PDF 时,响应的 statistics 部分还将包含 hyperlinks_count,告知您文档中存在多少个超链接。
{
"id":"entity_id",
"type":"TEXT",
"representation":{
"text":"document text",
"html":"document title document content",
"markdown":"# text"
},
"reading_order":2,
"page_indices":[
0
],
"locations":[
{
"page_index":0,
"bounding_box":{
"left":0.0,
"top":0.0,
"width":0.05,
"height":0.5
}
}
],
"sub_type":"TITLE/SECTION_TITLE/HEADER/FOOTER/PARAGRAPH/LIST/PAGE_NUMBER"
},
这是用于文档内文本的实体,由响应中的 TYPE 行表示。同样,representation 显示不同格式的文本。reading_order 显示读者按逻辑顺序查看文本的先后顺序。这是基于关联键和值的语义排序。例如,它按阅读顺序将段落标题与相应的段落相关联。page_indices 告诉您文本所在的页面。接下来是位置信息,如果在响应中启用了该信息,则会提供一个文本边界框。最后是实体子类型。此子类型提供有关检测到哪些类型的文本的更多详细信息。有关子类型的完整列表,请参阅“API 参考”。
{
"id":"entity_id",
"type":"TABLE",
"representation":{
"html":"table.../table",
"markdown":"| header | ...",
"text":"header \t header",
"csv":"header, header, header\n..."
},
"csv_s3_uri":"s3://",
"headers":[
"date",
"amount",
"description",
"total"
],
"reading_order":3,
"title":"Title of the table",
"footers":[
"the footers of the table"
],
"crop_images":[
"s3://bucket/prefix.png",
"s3://bucket/prefix.png"
],
"page_indices":[
0,
1
],
"locations":[
{
"page_index":0,
"bounding_box":{
"left":0,
"top":0,
"width":1,
"height":1
}
},
{
"page_index":1,
"bounding_box":{
"left":0,
"top":0,
"width":1,
"height":1
}
}
],
"sub_type":"TITLE/SECTION_TITLE/HEADER/FOOTER/PARAGRAPH/LIST/PAGE_NUMBER"
},
这是表实体的信息。除了位置信息、不同格式的文本、表和阅读顺序外,它们还专门返回 S3 存储桶中表的 csv 信息和裁剪图像。CSV 信息显示不同的页眉、页脚和标题。图像将被路由到 InvokeDataAutomation 请求中设置的前缀的 s3 存储桶。
{
"id":"entity_id",
"type":"FIGURE",
"summary":"",
"representation":{
"text":"document text",
"html":"document title document content",
"markdown":"# text"
},
"crop_images":[
"s3://bucket/prefix.png",
"s3://bucket/prefix.png"
],
"locations":[
{
"page_index":0,
"bounding_box":{
"left":0,
"top":0,
"width":1,
"height":1
}
}
],
"sub_type":"CHART",
"title":"figure title",
"rai_flag":"APPROVED/REDACTED/REJECTED",
"reading_order":1,
"page_indices":[
0
]
}
,
这是用于图的实体,例如文档图形和图表。与表类似,这些图将被裁剪并且图像将会发送到前缀中设置的 S3 存储桶。此外,对于标题文本还会收到 sub_type 和图标题响应,并且会指示它是哪种类型的图。
"pages":[
{
"id":"page_id",
"page_index":0,
"detected_page_number":1,
"representation":{
"text":"document text",
"html":"document title document content",
"markdown":"# text"
},
"statistics":{
"element_count":5,
"table_count":1,
"figure_count":1,
"word_count":1000,
"line_count":32
},
"asset_metadata":{
"rectified_image":"s3://bucket/prefix.png",
"rectified_image_width_pixels":1700,
"rectified_image_height_pixels":2200
}
}
],
我们通过标准输出提取的最后一个实体是页面。页面与文本实体相同,但额外包含页码,这是在页面上检测到的页码。
"text_lines":[
{
"id":"line_id",
"text":"line text",
"reading_order":1,
"page_index":0,
"locations":{
"page_index":0,
"bounding_box":{
"left":0,
"top":0,
"width":1,
"height":1
}
}
}
],
"text_words":[
{
"id":"word_id",
"text":"word text",
"line_id":"line_id",
"reading_order":1,
"page_index":0,
"locations":{
"page_index":0,
"bounding_box":{
"left":0,
"top":0,
"width":1,
"height":1
}
}
}
]
最后两个元素用于单独的文本部分。单词级别粒度会为每个单词返回响应,而默认输出仅报告文本行。
本节重点介绍您在文档文件 InvokeDataAutomation 上运行 API 操作时收到的不同响应对象。下面我们将分解响应对象的每个部分,然后查看示例文档的完整填充响应。我们将收到的第一部分是 metadata。
"metadata": {
"logical_subdocument_id": "1",
"semantic_modality": "DOCUMENT",
"number_of_pages": X,
"start_page_index": "1",
"end_page_index": X,
"file_type": "PDF"
},
上面的第一部分概述了与文档关联的元数据。由于同步 InvokeDataAutomation API 当前不支持文档拆分,因此 logical_subdocument_id 始终等于 1。
"document":{
"representation":{
"text":"document text",
"html":"document title document content",
"markdown":"# text"
},
"description":"document text",
"summary":"summary text",
"statistics":{
"element_count":5,
"table_count":1,
"figure_count":1,
"word_count":1000,
"line_count":32
}
},
上面的部分提供文档级别粒度的信息。description 和 summary 部分是基于文档生成的字段。representation 部分提供文档中各种格式样式的实际内容。最后,statistics 包含有关文档实际内容的信息,例如有多少语义元素,有多少图、单词、行等。
注意:与异步 InvokeDataAutomationAsync 请求不同,同步 InvokeDataAutomation 请求不支持在 S3 存储桶中返回 csv 信息和表的裁剪图像。
{
"id":"entity_id",
"type":"TEXT",
"representation":{
"text":"document text",
"html":"document title document content",
"markdown":"# text"
},
"reading_order":2,
"page_indices":[
0
],
"locations":[
{
"page_index":0,
"bounding_box":{
"left":0.0,
"top":0.0,
"width":0.05,
"height":0.5
}
}
],
"sub_type":"TITLE/SECTION_TITLE/HEADER/FOOTER/PARAGRAPH/LIST/PAGE_NUMBER"
},
这是用于文档内文本的实体,由响应中的 TYPE 行指示。再说一遍,表示形式以不同的格式显示文本。reading_order 显示读者何时能在逻辑上看到文本。这是基于关联键和值的语义排序。例如,它按阅读顺序将段落标题与相应的段落相关联。page_indices 会告诉你文本在哪些页面上。接下来是位置信息,如果在响应中启用了该信息,则会提供一个文本边界框。最后是实体子类型。此子类型提供有关检测到哪些类型的文本的更多详细信息。有关子类型的完整列表,请参阅“API 参考”。
{
"id": "entity_id",
"type": "TABLE",
"representation": {
"html": "table.../table",
"markdown": "| header | ...",
"text": "header \t header",
"csv": "header, header, header\n..."
},
"headers": ["date", "amount", "description", "total"],
"reading_order": 3,
"title": "Title of the table",
"footers": ["the footers of the table"],
"page_indices": [0, 1],
"locations": [{
"page_index": 0,
"bounding_box": {
"left": 0,
"top": 0,
"width": 1,
"height": 1
}
}, {
"page_index": 1,
"bounding_box": {
"left": 0,
"top": 0,
"width": 1,
"height": 1
}
}]
},
这是表实体的信息。CSV 信息显示不同的页眉、页脚和标题。
{
"id": "entity_id",
"type": "FIGURE",
"summary": "",
"representation": {
"text": "document text",
"html": "document title document content",
"markdown": "# text"
},
"locations": [
{
"page_index": 0,
"bounding_box": {
"left": 0,
"top": 0,
"width": 1,
"height": 1
}
}
],
"sub_type": "CHART",
"title": "figure title",
"reading_order": 1,
"page_indices": [
0
]
},
这是用于图的实体,例如文档图形和图表。您将收到标题文本的标题回复和图标题回复,并指示它是哪种图形。sub_type
"pages":[
"pages":[
{
"id":"page_id",
"page_index":0,
"detected_page_number":1,
"representation":{
"text":"document text",
"html":"document title document content",
"markdown":"# text"
},
"statistics":{
"element_count":5,
"table_count":1,
"figure_count":1,
"word_count":1000,
"line_count":32
},
"asset_metadata":{
"rectified_image":"s3://bucket/prefix.png",
"rectified_image_width_pixels":1700,
"rectified_image_height_pixels":2200
}
}
],
我们通过标准输出提取的最后一个实体是页面。页面与文本实体相同,但额外包含页码,这是在页面上检测到的页码。
"text_lines":[
{
"id":"line_id",
"text":"line text",
"reading_order":1,
"page_index":0,
"locations":{
"page_index":0,
"bounding_box":{
"left":0,
"top":0,
"width":1,
"height":1
}
}
}
],
"text_words":[
{
"id":"word_id",
"text":"word text",
"line_id":"line_id",
"reading_order":1,
"page_index":0,
"locations":{
"page_index":0,
"bounding_box":{
"left":0,
"top":0,
"width":1,
"height":1
}
}
}
]
最后两个元素用于单独的文本部分。单词级别粒度会为每个单词返回响应,而默认输出仅报告文本行。