Files
docling-core/tests/data/doc/multi_captions_footnotes.json
Panos Vagenas 9aa4a53580 fix(doclang): fix multi-caption/footnote (de)serialization (#797)
* test(doclang): add serialization test for multiple captions & footnotes

Add DoclingDocument fixtures with pictures, a table and a code block
carrying multiple captions and footnotes: above, below and beside their
host, interleaved, and without provenance. A mirrored fixture has them at
body level instead of as children of their host. Add a golden-file test
for their DocLang serialization.

Multiple captions are currently merged into a single <caption> element
with several locations, which fails DocLang schema validation and breaks
the deserialize/reserialize roundtrip. Until that is fixed, the test
compares against the golden file without schema validation, and the
roundtrip steps are commented out.

Signed-off-by: Panos Vagenas <pva@zurich.ibm.com>

* fix(doclang): serialize multiple captions and footnotes of a float as satellites

All captions of a picture/table were merged into its single <caption>,
yielding invalid DocLang, while those of a code block were escaped into
its content. Keep only the first caption in the element head and emit any
further captions as <text> and footnotes as <footnote> next to the host,
placed before or after it by bbox position, all wrapped in a <group>.

On deserialization, read such a group back as the float with its
captions and footnotes (a convention until DocLang supports this).

Enable schema validation and the roundtrip in the corresponding test.

Signed-off-by: Panos Vagenas <pva@zurich.ibm.com>

---------

Signed-off-by: Panos Vagenas <pva@zurich.ibm.com>
2026-09-24 09:43:21 +02:00

988 lines
21 KiB
JSON

{
"schema_name": "DoclingDocument",
"version": "1.10.0",
"name": "multi_captions_footnotes",
"furniture": {
"self_ref": "#/furniture",
"children": [],
"content_layer": "furniture",
"name": "_root_",
"label": "unspecified"
},
"body": {
"self_ref": "#/body",
"children": [
{
"$ref": "#/texts/0"
},
{
"$ref": "#/pictures/0"
},
{
"$ref": "#/tables/0"
},
{
"$ref": "#/pictures/1"
},
{
"$ref": "#/texts/17"
}
],
"content_layer": "body",
"name": "_root_",
"label": "unspecified"
},
"groups": [],
"texts": [
{
"self_ref": "#/texts/0",
"parent": {
"$ref": "#/body"
},
"children": [],
"content_layer": "body",
"label": "text",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 40.0,
"r": 500.0,
"b": 60.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
23
]
}
],
"orig": "Some introductory text.",
"text": "Some introductory text."
},
{
"self_ref": "#/texts/1",
"parent": {
"$ref": "#/pictures/0"
},
"children": [],
"content_layer": "body",
"label": "caption",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 360.0,
"r": 500.0,
"b": 372.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
27
]
}
],
"orig": "Figure 1, caption 1 (main).",
"text": "Figure 1, caption 1 (main)."
},
{
"self_ref": "#/texts/2",
"parent": {
"$ref": "#/pictures/0"
},
"children": [],
"content_layer": "body",
"label": "caption",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 390.0,
"r": 500.0,
"b": 402.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
28
]
}
],
"orig": "Figure 1, caption 2 (below).",
"text": "Figure 1, caption 2 (below)."
},
{
"self_ref": "#/texts/3",
"parent": {
"$ref": "#/pictures/0"
},
"children": [],
"content_layer": "body",
"label": "caption",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 110.0,
"r": 500.0,
"b": 122.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
28
]
}
],
"orig": "Figure 1, caption 3 (above).",
"text": "Figure 1, caption 3 (above)."
},
{
"self_ref": "#/texts/4",
"parent": {
"$ref": "#/pictures/0"
},
"children": [],
"content_layer": "body",
"label": "footnote",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 376.0,
"r": 500.0,
"b": 388.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
29
]
}
],
"orig": "Figure 1, footnote 1 (below).",
"text": "Figure 1, footnote 1 (below)."
},
{
"self_ref": "#/texts/5",
"parent": {
"$ref": "#/pictures/0"
},
"children": [],
"content_layer": "body",
"label": "footnote",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 404.0,
"r": 500.0,
"b": 416.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
29
]
}
],
"orig": "Figure 1, footnote 2 (below).",
"text": "Figure 1, footnote 2 (below)."
},
{
"self_ref": "#/texts/6",
"parent": {
"$ref": "#/pictures/0"
},
"children": [],
"content_layer": "body",
"label": "footnote",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 124.0,
"r": 500.0,
"b": 136.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
29
]
}
],
"orig": "Figure 1, footnote 3 (above).",
"text": "Figure 1, footnote 3 (above)."
},
{
"self_ref": "#/texts/7",
"parent": {
"$ref": "#/pictures/0"
},
"children": [],
"content_layer": "body",
"label": "caption",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 20.0,
"t": 280.0,
"r": 95.0,
"b": 300.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
27
]
}
],
"orig": "Figure 1, caption 4 (left).",
"text": "Figure 1, caption 4 (left)."
},
{
"self_ref": "#/texts/8",
"parent": {
"$ref": "#/pictures/0"
},
"children": [],
"content_layer": "body",
"label": "footnote",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 505.0,
"t": 160.0,
"r": 590.0,
"b": 180.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
29
]
}
],
"orig": "Figure 1, footnote 4 (right).",
"text": "Figure 1, footnote 4 (right)."
},
{
"self_ref": "#/texts/9",
"parent": {
"$ref": "#/tables/0"
},
"children": [],
"content_layer": "body",
"label": "caption",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 450.0,
"r": 500.0,
"b": 462.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
26
]
}
],
"orig": "Table 1, caption 1 (main).",
"text": "Table 1, caption 1 (main)."
},
{
"self_ref": "#/texts/10",
"parent": {
"$ref": "#/tables/0"
},
"children": [],
"content_layer": "body",
"label": "caption",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 585.0,
"r": 500.0,
"b": 597.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
27
]
}
],
"orig": "Table 1, caption 2 (below).",
"text": "Table 1, caption 2 (below)."
},
{
"self_ref": "#/texts/11",
"parent": {
"$ref": "#/tables/0"
},
"children": [],
"content_layer": "body",
"label": "footnote",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 600.0,
"r": 500.0,
"b": 612.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
28
]
}
],
"orig": "Table 1, footnote 1 (below).",
"text": "Table 1, footnote 1 (below)."
},
{
"self_ref": "#/texts/12",
"parent": {
"$ref": "#/tables/0"
},
"children": [],
"content_layer": "body",
"label": "footnote",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 614.0,
"r": 500.0,
"b": 626.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
28
]
}
],
"orig": "Table 1, footnote 2 (below).",
"text": "Table 1, footnote 2 (below)."
},
{
"self_ref": "#/texts/13",
"parent": {
"$ref": "#/pictures/1"
},
"children": [],
"content_layer": "body",
"label": "caption",
"prov": [],
"orig": "Figure 2, caption 1.",
"text": "Figure 2, caption 1."
},
{
"self_ref": "#/texts/14",
"parent": {
"$ref": "#/pictures/1"
},
"children": [],
"content_layer": "body",
"label": "caption",
"prov": [],
"orig": "Figure 2, caption 2.",
"text": "Figure 2, caption 2."
},
{
"self_ref": "#/texts/15",
"parent": {
"$ref": "#/pictures/1"
},
"children": [],
"content_layer": "body",
"label": "footnote",
"prov": [],
"orig": "Figure 2, footnote 1.",
"text": "Figure 2, footnote 1."
},
{
"self_ref": "#/texts/16",
"parent": {
"$ref": "#/pictures/1"
},
"children": [],
"content_layer": "body",
"label": "footnote",
"prov": [],
"orig": "Figure 2, footnote 2.",
"text": "Figure 2, footnote 2."
},
{
"self_ref": "#/texts/17",
"parent": {
"$ref": "#/body"
},
"children": [
{
"$ref": "#/texts/18"
},
{
"$ref": "#/texts/19"
},
{
"$ref": "#/texts/20"
},
{
"$ref": "#/texts/21"
}
],
"content_layer": "body",
"label": "code",
"prov": [
{
"page_no": 2,
"bbox": {
"l": 100.0,
"t": 200.0,
"r": 500.0,
"b": 300.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
14
]
}
],
"orig": "print('hello')",
"text": "print('hello')",
"captions": [
{
"$ref": "#/texts/18"
},
{
"$ref": "#/texts/19"
}
],
"references": [],
"footnotes": [
{
"$ref": "#/texts/20"
},
{
"$ref": "#/texts/21"
}
],
"code_language": "unknown"
},
{
"self_ref": "#/texts/18",
"parent": {
"$ref": "#/texts/17"
},
"children": [],
"content_layer": "body",
"label": "caption",
"prov": [
{
"page_no": 2,
"bbox": {
"l": 100.0,
"t": 170.0,
"r": 500.0,
"b": 182.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
28
]
}
],
"orig": "Listing 1, caption 1 (main).",
"text": "Listing 1, caption 1 (main)."
},
{
"self_ref": "#/texts/19",
"parent": {
"$ref": "#/texts/17"
},
"children": [],
"content_layer": "body",
"label": "caption",
"prov": [
{
"page_no": 2,
"bbox": {
"l": 100.0,
"t": 310.0,
"r": 500.0,
"b": 322.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
29
]
}
],
"orig": "Listing 1, caption 2 (below).",
"text": "Listing 1, caption 2 (below)."
},
{
"self_ref": "#/texts/20",
"parent": {
"$ref": "#/texts/17"
},
"children": [],
"content_layer": "body",
"label": "footnote",
"prov": [
{
"page_no": 2,
"bbox": {
"l": 100.0,
"t": 326.0,
"r": 500.0,
"b": 338.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
30
]
}
],
"orig": "Listing 1, footnote 1 (below).",
"text": "Listing 1, footnote 1 (below)."
},
{
"self_ref": "#/texts/21",
"parent": {
"$ref": "#/texts/17"
},
"children": [],
"content_layer": "body",
"label": "footnote",
"prov": [
{
"page_no": 2,
"bbox": {
"l": 100.0,
"t": 150.0,
"r": 500.0,
"b": 162.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
30
]
}
],
"orig": "Listing 1, footnote 2 (above).",
"text": "Listing 1, footnote 2 (above)."
}
],
"pictures": [
{
"self_ref": "#/pictures/0",
"parent": {
"$ref": "#/body"
},
"children": [
{
"$ref": "#/texts/1"
},
{
"$ref": "#/texts/2"
},
{
"$ref": "#/texts/3"
},
{
"$ref": "#/texts/4"
},
{
"$ref": "#/texts/5"
},
{
"$ref": "#/texts/6"
},
{
"$ref": "#/texts/7"
},
{
"$ref": "#/texts/8"
}
],
"content_layer": "body",
"label": "picture",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 150.0,
"r": 500.0,
"b": 350.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
0
]
}
],
"captions": [
{
"$ref": "#/texts/1"
},
{
"$ref": "#/texts/2"
},
{
"$ref": "#/texts/3"
},
{
"$ref": "#/texts/7"
}
],
"references": [],
"footnotes": [
{
"$ref": "#/texts/4"
},
{
"$ref": "#/texts/5"
},
{
"$ref": "#/texts/6"
},
{
"$ref": "#/texts/8"
}
],
"annotations": []
},
{
"self_ref": "#/pictures/1",
"parent": {
"$ref": "#/body"
},
"children": [
{
"$ref": "#/texts/13"
},
{
"$ref": "#/texts/14"
},
{
"$ref": "#/texts/15"
},
{
"$ref": "#/texts/16"
}
],
"content_layer": "body",
"label": "picture",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 650.0,
"r": 500.0,
"b": 750.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
0
]
}
],
"captions": [
{
"$ref": "#/texts/13"
},
{
"$ref": "#/texts/14"
}
],
"references": [],
"footnotes": [
{
"$ref": "#/texts/15"
},
{
"$ref": "#/texts/16"
}
],
"annotations": []
}
],
"tables": [
{
"self_ref": "#/tables/0",
"parent": {
"$ref": "#/body"
},
"children": [
{
"$ref": "#/texts/9"
},
{
"$ref": "#/texts/10"
},
{
"$ref": "#/texts/11"
},
{
"$ref": "#/texts/12"
}
],
"content_layer": "body",
"label": "table",
"prov": [
{
"page_no": 1,
"bbox": {
"l": 100.0,
"t": 480.0,
"r": 500.0,
"b": 580.0,
"coord_origin": "TOPLEFT"
},
"charspan": [
0,
0
]
}
],
"captions": [
{
"$ref": "#/texts/9"
},
{
"$ref": "#/texts/10"
}
],
"references": [],
"footnotes": [
{
"$ref": "#/texts/11"
},
{
"$ref": "#/texts/12"
}
],
"data": {
"table_cells": [
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 0,
"end_row_offset_idx": 1,
"start_col_offset_idx": 0,
"end_col_offset_idx": 1,
"text": "Name",
"column_header": true,
"row_header": false,
"row_section": false,
"fillable": false
},
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 0,
"end_row_offset_idx": 1,
"start_col_offset_idx": 1,
"end_col_offset_idx": 2,
"text": "Value",
"column_header": true,
"row_header": false,
"row_section": false,
"fillable": false
},
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 1,
"end_row_offset_idx": 2,
"start_col_offset_idx": 0,
"end_col_offset_idx": 1,
"text": "alpha",
"column_header": false,
"row_header": false,
"row_section": false,
"fillable": false
},
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 1,
"end_row_offset_idx": 2,
"start_col_offset_idx": 1,
"end_col_offset_idx": 2,
"text": "1",
"column_header": false,
"row_header": false,
"row_section": false,
"fillable": false
},
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 2,
"end_row_offset_idx": 3,
"start_col_offset_idx": 0,
"end_col_offset_idx": 1,
"text": "beta",
"column_header": false,
"row_header": false,
"row_section": false,
"fillable": false
},
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 2,
"end_row_offset_idx": 3,
"start_col_offset_idx": 1,
"end_col_offset_idx": 2,
"text": "2",
"column_header": false,
"row_header": false,
"row_section": false,
"fillable": false
}
],
"num_rows": 3,
"num_cols": 2,
"orientation": "rot_0",
"grid": [
[
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 0,
"end_row_offset_idx": 1,
"start_col_offset_idx": 0,
"end_col_offset_idx": 1,
"text": "Name",
"column_header": true,
"row_header": false,
"row_section": false,
"fillable": false
},
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 0,
"end_row_offset_idx": 1,
"start_col_offset_idx": 1,
"end_col_offset_idx": 2,
"text": "Value",
"column_header": true,
"row_header": false,
"row_section": false,
"fillable": false
}
],
[
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 1,
"end_row_offset_idx": 2,
"start_col_offset_idx": 0,
"end_col_offset_idx": 1,
"text": "alpha",
"column_header": false,
"row_header": false,
"row_section": false,
"fillable": false
},
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 1,
"end_row_offset_idx": 2,
"start_col_offset_idx": 1,
"end_col_offset_idx": 2,
"text": "1",
"column_header": false,
"row_header": false,
"row_section": false,
"fillable": false
}
],
[
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 2,
"end_row_offset_idx": 3,
"start_col_offset_idx": 0,
"end_col_offset_idx": 1,
"text": "beta",
"column_header": false,
"row_header": false,
"row_section": false,
"fillable": false
},
{
"row_span": 1,
"col_span": 1,
"start_row_offset_idx": 2,
"end_row_offset_idx": 3,
"start_col_offset_idx": 1,
"end_col_offset_idx": 2,
"text": "2",
"column_header": false,
"row_header": false,
"row_section": false,
"fillable": false
}
]
]
},
"annotations": []
}
],
"key_value_items": [],
"form_items": [],
"pages": {
"1": {
"size": {
"width": 600.0,
"height": 800.0
},
"page_no": 1
},
"2": {
"size": {
"width": 600.0,
"height": 800.0
},
"page_no": 2
}
}
}