feat: honour a reading order supplied by an upstream stage - #4153
Draft
wittjeff wants to merge 1 commit into
Draft
feat: honour a reading order supplied by an upstream stage#4153wittjeff wants to merge 1 commit into
wittjeff wants to merge 1 commit into
Conversation
Some stages already know the order of a page: a layout model that predicts reading order (docling-project#3958), the structure tree of a tagged PDF, or native form widgets. Add Cluster.reading_order and let the reading-order stage sort any page whose every element carries an index by that index, per sibling group, while pages with any unindexed element go through the predictor as before. Caption, footnote and merge mapping still run on the combined result. No index anywhere means no behaviour change. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Jeff Witt <1848307+wittjeff@users.noreply.github.com>
Contributor
|
✅ DCO Check Passed Thanks @wittjeff, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the mechanism proposed in #3958: let a stage upstream of reading order supply the order of a page, instead of the reading-order stage recomputing it.
What
Cluster.reading_order: int | None = None. Any stage that knows the order of a page sets it: a layout model that predicts reading order (PP-DocLayoutV3, [Feature] Support defining reading order from the layout stage #3958, Add support for PP-DocLayout-V3 layout detection and polygon bounding boxes. #3224), the structure tree of a tagged PDF (Proposal: tagged-PDF structure ingestion for PDF/UA-2 beyond forms (companion to #4143) #4146, feat(pdf): derive layout, heading levels and alt text from the tagged-PDF structure tree #4148), native form widgets inside a field region (feat: integrate native AcroForm widgets as typed fields #4140).ReadingOrderModel._order_siblings: within each sibling group (top level or the children of a container), a page whose every element carries an index is sorted by it; every other page goes through the predictor together, as before. Pages are concatenated in page order, which is also how the predictor lays out its result.Rules
Relation to #3233
reorder_elements=Falsethere is the degenerate case where postprocessor order is the supplied order for every page. This PR does not add that flag; it can be layered on top, or #3233 rebased onto this.Tests
tests/test_readingorder_supplied_order.py:No in-tree producer sets the index yet; the tagged-structure stage in #4148 is the first consumer and will be rebased onto this once the field name and the per-page rule are agreed.
Checklist:
🤖 Generated with Claude Code