catch_overlapping_and_nested_bboxes labels each element f"{ix}. {element.category}", where ix counts across the whole document, and identify_overlapping_or_nesting_case recovers the category with type1[3:].strip() (unstructured/utils.py:503-504). From element 100 on, the category keeps part of the index: . Table for 100 to 999, 0. Table from 1000. Partitioning output does not change. The strings in the overlap report do, in overlapping_elements and overlapping_case.
from unstructured.documents.coordinates import PixelSpace
from unstructured.documents.elements import CoordinatesMetadata, ElementMetadata, NarrativeText, Table, Title
from unstructured.utils import catch_overlapping_and_nested_bboxes
def el(cls, text, box, page):
x1, y1, x2, y2 = box
pts = ((x1, y1), (x1, y2), (x2, y2), (x2, y1))
md = ElementMetadata(page_number=page, coordinates=CoordinatesMetadata(points=pts, system=PixelSpace(1000, 1000)))
return cls(text=text, metadata=md)
for n in (0, 100, 1000):
filler = [el(NarrativeText, f"filler {i}", (0, i, 5, i + 1), page=1) for i in range(n)]
pair = [el(Table, "cell a cell b", (0, 0, 500, 500), 2), el(Title, "cell a", (10, 10, 100, 50), 2)]
_, cases = catch_overlapping_and_nested_bboxes(filler + pair)
print(n, [(c["overlapping_elements"], c["overlapping_case"]) for c in cases])
$ python repro.py # at ddf4453, Python 3.13.15
0 [(['Table(ix=0)', 'Title(ix=1)'], 'nested Title in Table')]
100 [(['. Table(ix=100)', '. Title(ix=101)'], 'nested . Title in . Table')]
1000 [(['0. Table(ix=1000)', '1. Title(ix=1001)'], 'nested 1. Title in 0. Table')]
Splitting on the first ". " in those two lines fixes it and leaves the label construction in catch_overlapping_and_nested_bboxes, which #4445 edits, alone.
@cragwolfe, would you take a pull request with that change and the 100 and 1000 cases as tests?
catch_overlapping_and_nested_bboxeslabels each elementf"{ix}. {element.category}", whereixcounts across the whole document, andidentify_overlapping_or_nesting_caserecovers the category withtype1[3:].strip()(unstructured/utils.py:503-504). From element 100 on, the category keeps part of the index:. Tablefor 100 to 999,0. Tablefrom 1000. Partitioning output does not change. The strings in the overlap report do, inoverlapping_elementsandoverlapping_case.Splitting on the first
". "in those two lines fixes it and leaves the label construction incatch_overlapping_and_nested_bboxes, which #4445 edits, alone.@cragwolfe, would you take a pull request with that change and the 100 and 1000 cases as tests?