表の理解

「表の理解 (Table Understanding)」 エンリッチメントを適用して、文書内の表および表関連データに関する詳細情報を取得します。

以下のタスクにより、表情報を含む HTML フィールドが生成され、コレクションの「表の理解」エンリッチメントが自動的に適用されます。

  • Smart Document Understanding ツールを使用して、ユーザーがトレーニングまたは事前トレーニングした SDU モデルを定義すると、コレクション用に生成される html フィールドに Table Understanding エンリッチメントが適用されます。

  • 「契約の文書取得 (Document Retrieval for Contracts)」 プロジェクト・タイプを作成すると、事前にトレーニングされた SDU モデルがコレクションに自動的に適用されます。 その結果、 Table Understanding エンリッチメントが、コレクション用に生成される html フィールドに適用されます。

    詳しくは、 Smart Document Understanding を参照してください。

開始前に

コレクション内の文書には、テーブルの HTML 表現を持つフィールドが含まれている必要があります。 多くの場合、この情報は html フィールドに保管されます。 コレクションが CSV ファイルまたは JSON ファイルで構成されている場合、HTML 形式の表情報を含む html フィールド以外のフィールドが含まれている可能性があります。

表の理解エンリッチメントの適用

エンリッチメントは、表の HTML 表現を含むフィールドにのみ適用できます。

エンリッチメントを適用するには、以下の手順に従ってください

  1. ナビゲーション・ペインで、 「コレクションの管理」 ページを開き、コレクションをクリックして開きます。

  2. **「エンリッチメント (Enrichments)」**タブをクリックします。

  3. 「表の理解」 エンリッチメントを見つけます。

  4. フィールドリストから html フィールドを選択します。

    テーブルの HTML 表現を含むフィールドを選択します。

エンリッチの適用後、 Discovery で表に保管されている情報を検索する必要がある照会をサブミットすると、有効な結果を取得できます。

開発者は、API を使用して表を照会できます。 詳しくは、 照会パラメーター を参照してください。

API を使用して表の理解エンリッチメントを適用する方法について詳しくは、 API を使用したエンリッチメントの適用 を参照してください。

Python での表データの処理

IBMのオープン・ソース・ライブラリーである Text Extensions for Pandasを使用して、 Discovery の文書から解析された表を pandas DataFrame オブジェクトに読み込みます。 pandas DataFrame は、 Pythonでのダウンストリーム分析のために変換および操作できる形式で、2 次元表形式のデータを表すオブジェクトです。

例えば、多くの年次報告書文書の表から内容を抽出し、複数年の対象データ・ポイントを含む単一の表に再構成することができます。 詳しくは、 Structured Information Extraction from Tables in PDF Documents with Pandas and IBM Watson ブログ投稿 ( 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: 現行表内のセルの固有 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: 文書の属性を識別する配列。 配列内の各オブジェクトは、以下の 3 つの要素で構成されます。

        • type: 属性のタイプ。 取り得る値は、AddressCurrencyDateTimeDurationLocationNumberOrganizationPercentage、および 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 要素の配列内の複数の値は、想定される列ヘッダーの階層を示しています。

以下の表は、入力文書からの例示表です。

例*テーブル

表は次のように構成されています

テーブルの
*例のテーブルの解剖学

この表では、以下の構文が使用されています。

  • 太字テキストは列ヘッダーを示しています
  • _イタリック体_は行見出しを示す
  • スタイル設定なしのテキストは、本文セルを示しています

サービスからの出力は、例の最初の体細胞(つまり、値が 35.0% の3行目の最初の細胞)を以下のように表します

{
  "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