mirror of
https://github.com/docling-project/docling-core.git
synced 2026-11-18 20:27:00 +00:00
* Added ruff to dev dependencies Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Added ruff settings to pyproject.toml as in docling Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Cleanup uf pyproject.toml Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Copied settings for ruff pre-commit hooks from docling Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Excluded test/data/** from ruff formatting / linting Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * ruff format Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Added some ignore statements to pyproject.toml such that ruff check raises fewer issues Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * ruff check --fix Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Ignored some more rules Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Fixed the rest of the errors that would only concern 1 - 3 files Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Added another ignore related to df for DataFrame names Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Modified CONTRIBUTING.md such that black / isort are replaced by ruff Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Added UP045 to ignore list such that Optional[...] does not raise Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Moved .flake8 configs to pyproject.toml Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Moved autoflake to be used with ruff Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Moved all .flake8 settings to pyproject.toml to be compatible with ruff (i.e. no separate [tool.flake8] section Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Removed flake8 from .pre-commit hooks Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Applied ruff format (again); formatted some files as the line-length = 120 equals now what was set for the .flake8 settings Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Set max-complexity to 30 (as was originally) in the pyproject.toml as one linting check would fail Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Adding PD901 to ignore list such that pre-commit hooks run fully again Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * Replaced dtype | None syntax by Optional[dtype] in remaining places Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> * chore: fix 'test' ref in pyproject Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> * style: remove typing List, Set, Tuple, Dict Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> * style: remove UP015 check from ignore list Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> * style: remove UP034 check from ignore list Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> * style: normalize dashes in comments and docstrings Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> * style: remove PD901 check from ignore list Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> * style: remove C403 check from ignore list Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> * style: remove C403, C413, C416 check from ignore list Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> * style: remove E203, F811 check from ignore list Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> --------- Signed-off-by: Florian Schwarb <florian.schwarb@gmail.com> Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> Co-authored-by: Florian Schwarb <florian.schwarb@gmail.com> Co-authored-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
from docling_core.types.doc.base import BoundingBox
|
|
from docling_core.types.doc.document import TableData
|
|
|
|
# Table bbox - defines region of a table, everything outside will be ignored
|
|
table_bbox: BoundingBox = BoundingBox(l=0, t=0, r=100, b=175)
|
|
|
|
# List of regions that defines rows for table structure
|
|
rows: list[BoundingBox] = [
|
|
BoundingBox(l=1, t=1, r=99, b=25),
|
|
BoundingBox(l=1, t=25, r=99, b=50),
|
|
BoundingBox(l=1, t=50, r=99, b=75),
|
|
BoundingBox(l=1, t=75, r=99, b=99),
|
|
BoundingBox(l=1, t=100, r=99, b=149),
|
|
BoundingBox(l=1, t=150, r=99, b=175),
|
|
]
|
|
|
|
# List of regions that defines columns for table structure
|
|
cols: list[BoundingBox] = [
|
|
BoundingBox(l=1, t=1, r=25, b=149),
|
|
BoundingBox(l=25, t=1, r=50, b=149),
|
|
BoundingBox(l=50, t=1, r=75, b=149),
|
|
BoundingBox(l=75, t=1, r=99, b=149),
|
|
]
|
|
|
|
# List of regions that defines merged cells on top of row/clumn grid (spans)
|
|
merges: list[BoundingBox] = [
|
|
BoundingBox(l=0, t=0, r=50, b=25),
|
|
BoundingBox(l=50, t=0, r=99, b=25),
|
|
]
|
|
|
|
# (OPTIONAL) Semantic of a table - region that cover column headers
|
|
col_headers: list[BoundingBox] = [
|
|
BoundingBox(l=0, t=0, r=99, b=25),
|
|
]
|
|
|
|
# (OPTIONAL) Semantic of a table - region that cover row headers
|
|
row_headers: list[BoundingBox] = [
|
|
BoundingBox(l=0, t=0, r=50, b=150),
|
|
]
|
|
|
|
# (OPTIONAL) Semantic of a table - region that cover section rows
|
|
row_section: list[BoundingBox] = [
|
|
BoundingBox(l=1, t=75, r=99, b=99),
|
|
]
|
|
|
|
|
|
def test_regions_to_table_convert():
|
|
# Converts regions: rows, columns, merged cells
|
|
# into table_data structure,
|
|
# Adds semantics for regions of row_headers, col_headers, row_section
|
|
table_data = TableData.from_regions(
|
|
table_bbox=table_bbox,
|
|
rows=rows,
|
|
cols=cols,
|
|
merges=merges,
|
|
row_headers=row_headers,
|
|
col_headers=col_headers,
|
|
row_sections=row_section,
|
|
)
|
|
|
|
assert table_data.num_cols == 4
|
|
assert table_data.num_rows == 6
|
|
|
|
assert table_data.table_cells[0].bbox.l == 1.0
|
|
assert table_data.table_cells[0].bbox.t == 1.0
|
|
assert table_data.table_cells[0].bbox.r == 50.0
|
|
assert table_data.table_cells[0].bbox.b == 25.0
|
|
|
|
assert table_data.table_cells[0].col_span == 2
|
|
assert table_data.table_cells[0].column_header
|
|
assert table_data.table_cells[1].column_header
|
|
|
|
assert table_data.table_cells[10].row_header
|
|
assert table_data.table_cells[12].row_section
|
|
|
|
assert table_data.table_cells[17].bbox.l == 75.0
|
|
assert table_data.table_cells[17].bbox.t == 100.0
|
|
assert table_data.table_cells[17].bbox.r == 99.0
|
|
assert table_data.table_cells[17].bbox.b == 149.0
|