了解表
应用 表理解 扩充项以获取有关文档中的表和表相关数据的详细信息。
以下任务生成包含表信息的 HTML 字段,并自动将“表理解”扩充项应用于集合:
-
如果使用“智能文档理解”工具来定义用户训练或预训练的 SDU 模型,那么
Table Understanding
扩充项将应用于为集合生成的html
字段。 -
如果创建 Document Retrieval for Contract 项目类型,那么会自动将预先训练的 SDU 模型应用于集合。 因此,
Table Understanding
扩充项将应用于为集合生成的html
字段。有关更多信息,请参阅 智能文档理解。
准备工作
集合中的文档必须包含具有表的 HTML 表示的字段。 此信息通常存储在 html
字段中。 如果集合由 CSV 或 JSON 文件组成,那么它可能具有除 html
字段以外的字段,该字段包含 HTML 格式的表信息。
应用表理解扩充项
只能将扩充项应用于包含表的 HTML 表示的字段。
要应用增强功能,请完成以下步骤:
-
从导航窗格中,打开“管理集合”页面,然后单击集合以将其打开。
-
单击扩充项选项卡。
-
查找 表理解 扩充项。
-
从字段列表中选择
html
字段。选择包含表的 HTML 表示的字段。
应用扩充项后,您可以在提交需要 Discovery 来查找存储在表中的信息的查询时获取有效结果。
开发者可以使用 API 来查询表。 有关更多信息,请参阅 查询参数。
有关如何使用 API 应用表理解扩充项的更多信息,请参阅 使用 API 应用扩充项。
在 Python 中使用表格数据
使用 Text Extensions for Pandas(来自 IBM的开放式源代码库) 将从 Discovery 中的文档解析的表读取到 pandas DataFrame 对象中。 Pandas DataFrame 是一个对象,它以可在 Python中进行下游分析的转换和操作的形式表示二维表格数据。
例如,您可以从许多年度报告文档中的表中抽取内容,并将其重构为包含多年相关数据点的单个表。 有关更多信息,请阅读 Structured Information 解压缩 From Tables in PDF Documents with Pandas and IBM Watson 博客帖子 on Medium.com。
输出模式
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
:当前表中单元格的唯一标识。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
:当前表中单元格的唯一标识。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
:当前表中单元格的唯一标识。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
:当前表中单元格的唯一标识。 -
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
:表中键的唯一标识。location
:输入文档中键单元格的位置,由其begin
和end
索引来定义。text
:没有 HTML 标记的表单元格的文本内容。
-
value
:一个数组,用于指定键/值对的值。cell_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
元素数组中的多个值表示列标题可能的层次结构。
示例
下表是输入文档中的示例表。

表格内容如下:
{: caption="示例" caption-side="bottom"}剖析
表中使用了以下语法:
- 粗体文本表示列标题
- _斜体字_表示行标题
- 无格式文本表示正文单元格
服务输出代表示例的第一个体单元(即第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": [ ]
}
了解键/值对
表格中有时包含跨越多个表格单元的关键值对。 表格 理解功能可以检测以下类型的表格对。
-
相邻单元格中的简单键值对,如下表所示:
基本表 密钥 值 项目编号 123456789
日期 1/1/2019
数量 $1,000
-
同一单元格中的键和值对,如下表所示:
复杂表 键值对 键值对 项目编号: 123456789
金额: $1000
日期: 1/1/2019
地址: 123 Anywhere Dr