本節著重於您在文件檔案上執行 API 操作 InvokeDataAutomationAsync 時收到的不同回應物件。以下我們將細分回應物件的每個區段,然後查看範例文件的完整填入回應。我們會收到的第一個區段是 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
}
},
上述區段提供文件層級精細程度資訊。描述和摘要區段是根據文件產生的欄位。表示區段以各種格式樣式提供文件的實際內容。最後,統計資料包含文件實際內容的資訊,例如有多少語意元素、有多少圖片、單字、行等。
這是資料表實體的資訊。對於 InvokeDataAutomationAsync (非同步) 請求,除了位置資訊、文字、資料表和讀取順序的不同格式之外,它們還特別在 S3 儲存貯體中傳回資料表的 csv 資訊和裁切影像。CSV 資訊會顯示不同的標頭、頁尾和標題。影像將路由至 InvokeDataAutomationAsync 請求中設定字首的 s3 儲存貯體。對於 InvokeDataAutomation (同步) 請求,不支援 S3 儲存貯體中資料表的 csv 和裁剪映像。
當您處理 PDF 時,回應的統計資料區段也會包含 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 行表示。同樣地,表示法會以不同的格式顯示文字。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
}
}
}
]
最後兩個元素適用於個別文字部分。單字層級精細程度會傳回每個單字的回應,而預設輸出只會報告文字行。
本節著重於在文件檔案上執行 API 操作 InvokeDataAutomation 時收到的不同回應物件。以下我們將細分回應物件的每個區段,然後查看範例文件的完整填入回應。我們會收到的第一個區段是 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
}
},
上述區段提供文件層級精細程度資訊。描述和摘要區段是根據文件產生的欄位。表示區段以各種格式樣式提供文件的實際內容。最後,統計資料包含文件實際內容的資訊,例如有多少語意元素、有多少圖片、單字、行等。
注意:與非同步 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
}
}
}
]
最後兩個元素適用於個別文字部分。單字層級精細程度會傳回每個單字的回應,而預設輸出只會報告文字行。