mirror of
https://github.com/DS4SD/docling.git
synced 2025-07-26 03:55:00 +00:00
Detecting table orientation
Signed-off-by: Maksym Lysak <mly@zurich.ibm.com>
This commit is contained in:
parent
b3d111a3cd
commit
88a9756861
@ -219,6 +219,7 @@ class TableStructureModel(BasePageModel):
|
|||||||
}
|
}
|
||||||
|
|
||||||
table_clusters, table_bboxes = zip(*in_tables)
|
table_clusters, table_bboxes = zip(*in_tables)
|
||||||
|
table_orientaton_angle_360 = 0
|
||||||
|
|
||||||
if len(table_bboxes):
|
if len(table_bboxes):
|
||||||
for table_cluster, tbl_box in in_tables:
|
for table_cluster, tbl_box in in_tables:
|
||||||
@ -229,6 +230,25 @@ class TableStructureModel(BasePageModel):
|
|||||||
cell_unit=TextCellUnit.WORD,
|
cell_unit=TextCellUnit.WORD,
|
||||||
bbox=table_cluster.bbox,
|
bbox=table_cluster.bbox,
|
||||||
)
|
)
|
||||||
|
# Table cluster orientation, derived from cells...
|
||||||
|
tcells_orientations = {}
|
||||||
|
for tcell in tcells:
|
||||||
|
if tcell.rect.angle_360 not in tcells_orientations:
|
||||||
|
tcells_orientations[tcell.rect.angle_360] = 1
|
||||||
|
else:
|
||||||
|
tcells_orientations[tcell.rect.angle_360] += 1
|
||||||
|
# Most of the cells in table bbox have this orientation:
|
||||||
|
if len(tcells_orientations.keys()) > 0:
|
||||||
|
table_orientaton_angle_360 = max(
|
||||||
|
tcells_orientations,
|
||||||
|
key=tcells_orientations.__getitem__,
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"TABLE ORIENTATION: {}".format(
|
||||||
|
table_orientaton_angle_360
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if len(tcells) == 0:
|
if len(tcells) == 0:
|
||||||
# In case word-level cells yield empty
|
# In case word-level cells yield empty
|
||||||
tcells = table_cluster.cells
|
tcells = table_cluster.cells
|
||||||
|
Loading…
Reference in New Issue
Block a user