Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.26.4

### Fixes

- **Keep overlap labels aligned with coordinate-bearing elements**: `catch_overlapping_and_nested_bboxes()` now excludes elements without coordinates from the parallel label and text collections, matching the existing bounding-box filtering. Previously, a coordinate-less element before an overlapping pair shifted those collections and caused the report to name the wrong elements, texts, and parent-child relationship.

## 0.26.3

### Fixes
Expand Down
35 changes: 35 additions & 0 deletions test_unstructured/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,41 @@ def test_catch_overlapping_and_nested_bboxes_non_overlapping_case():
assert overlapping_cases == []


def test_catch_overlapping_and_nested_bboxes_ignores_elements_without_coordinates():
coordinate_system = PixelSpace(width=20, height=20)
elements = [
Title(
text="No coordinates",
metadata=ElementMetadata(page_number=1),
),
Title(
text="Parent",
coordinates=((1, 1), (1, 10), (10, 10), (10, 1)),
coordinate_system=coordinate_system,
metadata=ElementMetadata(page_number=1),
),
NarrativeText(
text="Child",
coordinates=((3, 3), (3, 5), (5, 5), (5, 3)),
coordinate_system=coordinate_system,
metadata=ElementMetadata(page_number=1),
),
]

overlapping_flag, overlapping_cases = utils.catch_overlapping_and_nested_bboxes(
elements,
nested_error_tolerance_px=1,
)

assert overlapping_flag is True
assert overlapping_cases[0]["overlapping_elements"] == [
"Title(ix=1)",
"NarrativeText(ix=2)",
]
assert overlapping_cases[0]["parent_element"] == "Title(ix=1)"
assert overlapping_cases[0]["overlapping_case"] == "nested NarrativeText in Title"


def test_only_returns_singleton_iterable():
singleton_iterable = [42]
result = utils.only(singleton_iterable)
Expand Down
2 changes: 1 addition & 1 deletion unstructured/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.26.3" # pragma: no cover
__version__ = "0.26.4" # pragma: no cover
4 changes: 2 additions & 2 deletions unstructured/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,8 @@ def catch_overlapping_and_nested_bboxes(
if element.metadata.coordinates:
box = cast(Points, element.metadata.coordinates.to_dict()["points"])
pages_of_bboxes[n_page_to_ix].append(box)
text_labels[n_page_to_ix].append(f"{ix}. {element.category}")
text_content[n_page_to_ix].append(element.text)
text_labels[n_page_to_ix].append(f"{ix}. {element.category}")
text_content[n_page_to_ix].append(element.text)

document_with_overlapping_flag = False
overlapping_cases: list[dict[str, Any]] = []
Expand Down