瞭解表格
套用 Table Understanding 強化,以取得文件內表格及表格相關資料的詳細資訊。
下列作業會產生含有表格資訊的 HTML 欄位,並針對您的集合自動將 Table Understanding 強化套用至該 HTML 欄位:
-
如果您使用「智慧型文件理解」工具來定義使用者訓練或預先訓練的 SDU 模型,則
Table Understanding強化會套用至針對集合產生的html欄位。 -
如果您建立 合約的文件擷取 專案類型,則會自動將預先訓練的 SDU 模型套用至集合。 因此,
Table Understanding強化會套用至針對集合產生的html欄位。如需相關資訊,請參閱 智慧型文件理解。
開始之前
集合中的文件必須包含具有表格的 HTML 表示法的欄位。 此資訊通常儲存在 html 欄位中。 如果您的集合是由 CSV 或 JSON 檔案所組成,則它可能具有 html 欄位以外的欄位,其中包含 HTML 格式的表格資訊。
套用表格瞭解強化
您只能將強化套用至包含表格的 HTML 表示法的欄位。
若要套用增益,請完成下列步驟:
-
從導覽窗格中,開啟 管理集合 頁面,然後按一下集合以開啟它。
-
按一下強化標籤。
-
尋找 Table Understanding 強化。
-
從欄位清單中選取
html欄位。選擇包含表格的 HTML 表示法的欄位。
套用強化之後,當您提交需要 Discovery 以尋找儲存在表格中的資訊的查詢時,可以取得有效的結果。
開發人員可以使用 API 來查詢表格。 如需相關資訊,請參閱 查詢參數。
如需如何使用 API 來套用表格瞭解強化的相關資訊,請參閱 使用 API 來套用強化。
在 Python 中使用表狀資料
使用 Text Extensions for Pandas(來自 IBM的開放程式碼程式庫),來讀取從 Discovery 中的文件剖析至 pandas DataFrame 物件的表格。 Pandas DataFrame 是一個物件,以可針對 Python中的下游分析進行轉換及操作的形式代表二維表格資料。
例如,您可以從許多年度報告文件中的表格擷取內容,並將它重新建構成單一表格,其中包含感興趣的多年資料點。 如需相關資訊,請閱讀 Medium.com上的 Structured Information Extraction from Tables in PDF Documents with Pandas and IBM Watson 部落格文章。
輸出綱目
Table Understanding 強化中的輸出綱目如下所示。
{
"tables": [
{
"location" : {
"begin" : int,
"end" : int
},
"text": string,
"section_title": {
"text": string,
"location": {
"begin" : int,
"end" : int
}
},
"title": {
"location": {
"begin": int,
"end": int,
},
"text": string
},
"table_headers" : [
{
"cell_id" : string,
"location" : {
"begin" : int,
"end" : int
},
"text" : string,
"row_index_begin" : int,
"row_index_end" : int,
"column_index_begin" : int,
"column_index_end" : int
},
...
],
"column_headers" : [
{
"cell_id" : string,
"location" : {
"begin" : int,
"end" : int
},
"text" : string,
"text_normalized" : string,
"row_index_begin" : int,
"row_index_end" : int,
"column_index_begin" : int,
"column_index_end" : int
},
...
],
"row_headers" : [
{
"cell_id" : string,
"location" : {
"begin" : int,
"end" : int
},
"text" : string,
"text_normalized" : string,
"row_index_begin" : int,
"row_index_end" : int,
"column_index_begin" : int,
"column_index_end" : int
},
...
],
"body_cells" : [
{
"cell_id" : string,
"location" : {
"begin" : int,
"end" : int
},
"text" : string,
"row_index_begin" : int,
"row_index_end" : int,
"column_index_begin" : int,
"column_index_end" : int,
"row_header_ids": [ string ],
"row_header_texts": [ string ],
"row_header_texts_normalized": [ string ],
"column_header_ids": [ string ],
"column_header_texts": [ string ],
"column_header_texts_normalized": [ string ],
"attributes" : [
{
"type" : string,
"text" : string,
"location" : {
"begin" : int,
"end" : int
}
},
...
]
},
...
],
"key_value_pairs": [
{
"key": {
"cell_id": string,
"location": {
"begin": int,
"end": int
},
"text": string
},
"value": [{
"cell_id": string,
"location": {
"begin": int,
"end": int
},
"text": string
},
...
]
},
...
],
"contexts": [
{
"text": string,
"location": {
"begin": int,
"end": int
}
},
...
]
}
]
}
綱目排列
綱目的排列方式如下。
-
tables:定義輸入文件中識別的表格的陣列。-
location:現行表格在輸入文件中的位置,如其begin和end索引所定義。 -
text:輸入文件中現行表格的文字內容,不含相關聯的標記內容。 -
section_title:如果識別到包含在現行表格中的區段標題,則為該區段標題的位置。 如果未識別任何區段標題,則為空白。text:所識別區段標題的文字。location:區段標題在輸入文件中的位置,如其begin和end索引所定義。
-
title:Table x.: ...。 未識別標題時為空。 出現時,title會從同表的contexts陣列中排除。location:標題在輸入文件中的位置,如其begin和end索引所定義。text:所識別表格標題的文字。
-
table_headers:表格層次資料格的陣列,這些資料格適合作為現行表格之所有其他資料格的標頭。 每個表格標頭都定義為下列元素的集合:cell_id:資料格在現行表格中的唯一 ID。location:資料格在輸入文件中的位置,如其begin和end索引所定義。text:輸入文件中資料格的文字內容,不含相關聯的標記內容。row_index_begin:資料格在現行表格中之begin位置的row索引。row_index_end:資料格在現行表格中之end位置的row索引。column_index_begin:資料格在現行表格中之begin位置的column索引。column_index_end:資料格在現行表格中之end位置的column索引。
-
column_headers:現行表格之直欄層次資料格的陣列,每個都適合作為與其本身相同直欄之其他資料格的標頭。 每個直欄標頭定義為下列項目的集合:cell_id:資料格在現行表格中的唯一 ID。location:資料格在輸入文件中的位置,如其begin和end索引所定義。text:輸入文件中資料格的文字內容,不含相關聯的標記內容。text_normalized: 正規化直欄標頭文字。row_index_begin:資料格在現行表格中之begin位置的row索引。row_index_end:資料格在現行表格中之end位置的row索引。column_index_begin:資料格在現行表格中之begin位置的column索引。column_index_end:資料格在現行表格中之end位置的column索引。
-
row_headers:現行表格之列層次資料格的陣列,每個都適合作為與其本身相同列之其他資料格的標頭。 每個列標頭定義為下列項目的集合:cell_id:資料格在現行表格中的唯一 ID。location:資料格在輸入文件中的位置,如其begin和end索引所定義。text:輸入文件中資料格的文字內容,不含相關聯的標記內容。text_normalized: 正規化列標頭文字。row_index_begin:資料格在現行表格中之begin位置的row索引。row_index_end:資料格在現行表格中之end位置的row索引。column_index_begin:資料格在現行表格中之begin位置的column索引。column_index_end:資料格在現行表格中之end位置的column索引。
-
body_cells:不是現行表格之表格標頭、直欄標頭或列標頭資料格的資料格陣列,含相對應的列與直欄標頭關聯。 每個內文資料格定義為下列項目的集合:-
cell_id:資料格在現行表格中的唯一 ID。 -
location:資料格在輸入文件中的位置,如其begin和end索引所定義。 -
text:輸入文件中資料格的文字內容,不含相關聯的標記內容。 -
row_index_begin:這個資料格在現行表格中之begin位置的row索引。 -
row_index_end:這個資料格在現行表格中之end位置的row索引。 -
column_index_begin:這個資料格在現行表格中之begin位置的column索引。 -
column_index_end:這個資料格在現行表格中之end位置的column索引。 -
row_header_ids:數值陣列,其中每個數值是與此正體儲存格相關的行標頭的儲存格 ID 值。 -
row_header_texts: 值陣列,其中每一個值都是來自此內文資料格之列標頭的文字。 -
row_header_texts_normalized: 值陣列,其中每一個值都是來自此內文資料格之列標頭的正規化文字。 -
column_header_ids:數值陣列,其中每個數值是與此正體儲存格相關的列頭的儲存格 ID 值。 -
column_header_texts: 值陣列,其中每一個值都是此內文資料格的直欄標頭中的文字。 -
column_header_texts_normalized: 值陣列,其中每一個值都是此內文資料格之直欄標頭中的正規化文字。 -
attributes:識別文件屬性的陣列。 陣列中的每個物件都是由三個元素組成:type:屬性的類型。 可能值為Address、Currency、DateTime、Duration、Location、Number、Organization、Percentage及Person。text:與屬性相關聯的文字。location:屬性的位置,如其begin和end索引所定義。
-
-
key_value_pairs:指定輸入文件之表格中任何鍵值組的陣列。 如需相關資訊,請參閱瞭解鍵值組。-
key:指定鍵值組之索引鍵的物件。cell_id:索引鍵在表格中的唯一 ID。location:索引鍵資料格在輸入文件中的位置,如其begin和end索引所定義。text:表格資料格的文字內容,不含 HTML 標記。
-
value:指定鍵值組之一個以上值的陣列。cell_id:值在表格中的唯一 ID。location:值資料格在輸入文件中的位置,如其begin和end索引所定義。text:表格資料格的文字內容,不含 HTML 標記。
-
-
contexts:表格前面和後面的相關資料清單,不包括其節標題(在section_title欄位中提供)。 相關資料包括相關的句子、註腳,以及來自參照表格之文件其他部分的句子。 該清單以陣列形式代表。 陣列中的每個物件都包含下列元素:text:輸入文件中相關資料的文字內容,不含 HTML 標記。location:相關資料在輸入文件中的位置,如其begin和end索引所定義。
-
關於表格輸出綱目的附註
- 每個資料格的列和直欄索引值都以零為基礎,因此從
0開始。 row_header_ids和row_header_texts元素陣列中的多個值表示列標頭可能的階層。column_header_ids和column_header_texts元素陣列中的多個值表示直欄標頭可能的階層。
範例
下表為輸入文件中的範例表格。
表格組成如下:
表格中使用下列語法:
- 粗體字指出直欄標頭
- _斜體文字_表示行頭
- 無格式文字指出內文資料格
service 的輸出表示範例的第一個正體儲存格 (即第 3 行第一個儲存格,其值為 35.0% ),如下所示:
{
"tables": [ {
"location": {
"begin": 872,
"end": 5879
},
"text": "...",
"section_title": {
"text": "",
"location": {
"begin": 0,
"end": 0
}
},
"table_headers" : [ ],
"column_headers" : [ {
"cell_id" : "colHeader-1050-1082",
"location" : {
"begin" : 1050,
"end" : 1083
},
"text" : "Three months ended September 30,",
"text_normalized" : "Three months ended September 30,",
"row_index_begin" : 0,
"row_index_end" : 0,
"column_index_begin" : 1,
"column_index_end" : 2
}, {
"cell_id" : "colHeader-1270-1301",
"location" : {
"begin" : 1270,
"end" : 1302
},
"text" : "Nine months ended September 30,",
"text_normalized" : "Nine months ended September 30,",
"row_index_begin" : 0,
"row_index_end" : 0,
"column_index_begin" : 3,
"column_index_end" : 4
}, {
"cell_id" : "colHeader-1544-1548",
"location" : {
"begin" : 1544,
"end" : 1549
},
"text" : "2005",
"text_normalized" : "Year 1",
"row_index_begin" : 1,
"row_index_end" : 1,
"column_index_begin" : 1,
"column_index_end" : 1
}, {
"cell_id" : "colHeader-1712-1716",
"location" : {
"begin" : 1712,
"end" : 1717
},
"text" : "2004",
"text_normalized" : "Year 2",
"row_index_begin" : 1,
"row_index_end" : 1,
"column_index_begin" : 2,
"column_index_end" : 2
}, {
"cell_id" : "colHeader-1889-1893",
"location" : {
"begin" : 1889,
"end" : 1894
},
"text" : "2005",
"text_normalized" : "Year 1",
"row_index_begin" : 1,
"row_index_end" : 1,
"column_index_begin" : 3,
"column_index_end" : 3
}, {
"cell_id" : "colHeader-2057-2061",
"location" : {
"begin" : 2057,
"end" : 2062
},
"text" : "2004",
"text_normalized" : "Year 2",
"row_index_begin" : 1,
"row_index_end" : 1,
"column_index_begin" : 4,
"column_index_end" : 4
} ],
"row_headers" : [ {
"cell_id" : "rowHeader-2244-2262",
"location" : {
"begin" : 2244,
"end" : 2263
},
"text" : "Statutory tax rate",
"text_normalized" : "Statutory tax rate",
"row_index_begin" : 2,
"row_index_end" : 2,
"column_index_begin" : 0,
"column_index_end" : 0
}, {
"cell_id" : "rowHeader-3197-3217",
"location" : {
"begin" : 3197,
"end" : 3218
},
"text" : "IRS audit settlement",
"text_normalized" : "IRS audit settlement",
"row_index_begin" : 3,
"row_index_end" : 3,
"column_index_begin" : 0,
"column_index_end" : 0
}, {
"cell_id" : "rowHeader-4148-4176",
"location" : {
"begin" : 4148,
"end" : 4177
},
"text" : "Dividends received deduction",
"text_normalized" : "Dividends received deduction",
"row_index_begin" : 4,
"row_index_end" : 4,
"column_index_begin" : 0,
"column_index_end" : 0
}, {
"cell_id" : "rowHeader-5106-5130",
"location" : {
"begin" : 5106,
"end" : 5131
},
"text" : "Total effective tax rate",
"text_normalized" : "Total effective tax rate",
"row_index_begin" : 5,
"row_index_end" : 5,
"column_index_begin" : 0,
"column_index_end" : 0
} ],
"key_value_pairs" : [ ],
"body_cells" : [ {
"cell_id" : "bodyCell-2450-2455",
"location" : {
"begin" : 2450,
"end" : 2456
},
"text" : "35.0%",
"row_index_begin" : 2,
"row_index_end" : 2,
"column_index_begin" : 1,
"column_index_end" : 1,
"row_header_ids" : [ "rowHeader-2244-2262" ],
"row_header_texts" : [ "Statutory tax rate" ],
"row_header_texts_normalized" : [ "Statutory tax rate" ],
"column_header_ids" : [ "colHeader-1050-1082", "colHeader-1544-1548" ],
"column_header_texts" : [ "Three months ended September 30,", "2005" ],
"column_header_texts_normalized" : [ "Three months ended September 30,", "Year 1" ],
"attributes": [ ]
}, {
"cell_id" : "bodyCell-2633-2638",
"location" : {
"begin" : 2633,
"end" : 2639
},
"text" : "35.0%",
"row_index_begin" : 2,
"row_index_end" : 2,
"column_index_begin" : 2,
"column_index_end" : 2,
"row_header_ids" : [ "rowHeader-2244-2262" ],
"row_header_texts" : [ "Statutory tax rate" ],
"row_header_texts_normalized" : [ "Statutory tax rate" ],
"column_header_ids" : [ "colHeader-1050-1082", "colHeader-1712-1716" ],
"column_header_texts" : [ "Three months ended September 30,", "2004" ],
"column_header_texts_normalized" : [ "Three months ended September 30,", "Year 2" ],
"attributes": [ ]
}, {
"cell_id" : "bodyCell-2825-2830",
"location" : {
"begin" : 2825,
"end" : 2831
},
"text" : "35.0%",
"row_index_begin" : 2,
"row_index_end" : 2,
"column_index_begin" : 3,
"column_index_end" : 3,
"row_header_ids" : [ "rowHeader-2244-2262" ],
"row_header_texts" : [ "Statutory tax rate" ],
"row_header_texts_normalized" : [ "Statutory tax rate" ],
"column_header_ids" : [ "colHeader-1270-1301", "colHeader-1889-1893" ],
"column_header_texts" : [ "Nine months ended September 30,", "2005" ],
"column_header_texts_normalized" : [ "Nine months ended September 30,", "Year 1" ],
"attributes": [ ]
}, {
"cell_id" : "bodyCell-3008-3013",
"location" : {
"begin" : 3008,
"end" : 3014
},
"text" : "35.0%",
"row_index_begin" : 2,
"row_index_end" : 2,
"column_index_begin" : 4,
"column_index_end" : 4,
"row_header_ids" : [ "rowHeader-2244-2262" ],
"row_header_texts" : [ "Statutory tax rate" ],
"row_header_texts_normalized" : [ "Statutory tax rate" ],
"column_header_ids" : [ "colHeader-1270-1301", "colHeader-2057-2061" ],
"column_header_texts" : [ "Nine months ended September 30,", "2004" ],
"column_header_texts_normalized" : [ "Nine months ended September 30,", "Year 2" ],
"attributes": [ ]
},
...
],
"contexts": [ ]
}
瞭解鍵值組
表格有時包含跨越多個表格單元格的鍵值對。 Table Understanding 可以偵測下列類型的表格對。
-
相鄰單元格中的簡單鍵值對,如以下範例表格:
基本表格 索引鍵 值 項目號碼 123456789Date 1/1/2019量 $1,000 -
在同一個儲存格中的鍵和值對,如以下範例表格:
複式表格 鍵值組 鍵值組 項目編號: 123456789金額: $1000日期: 1/1/2019地址: 123 Anywhere Dr