Repository navigation
fix(pdf): keep a line-final hyphen that belongs to the word - #4387
stanleys12 wants to merge 5 commits into
Conversation
Both sites that close up a word split over a line break dropped the hyphen whenever alphanumerics stood on either side, so a hyphen that is part of the word was destroyed: "n-" / "octanal" became "noctanal" and "pages 15137-" / "15145" became "pages 1513715145". Two shapes of hyphen cannot have come from hyphenation and are now kept at both sites: one after a single-character token, which no typesetter produces, and one before a continuation opening on a digit. Regenerate the three PDF reference documents the change affects. Every difference restores a hyphen: five page ranges and one "x-coordinate". Signed-off-by: Stanley Shen <sshen37@ucsc.edu> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
✅ DCO Check Passed Thanks @stanleys12, all your commits are properly signed off. 🎉 |
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ression-2-118-0-permane-d3ce Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Stanley Shen <stanleyshen1886@gmail.com>
The reference documents added on main include an 'n-' / 'ft' line break in newspaper-00, which now keeps its hyphen after the single-character token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Stanley Shen <stanleyshen1886@gmail.com>
|
/ai review |
AI triage (advisory)Checked commit Warning The AI analysis did not finish. Only the deterministic checks are shown. CI safety: not assessed. Possibly related pull requests
Reference data changes
The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 03c6d1df07. It read the code and did not run it.
I checked the line-final hyphen retention logic in docling/models/stages/page_assemble/page_assemble_model.py and docling/models/stages/reading_order/readingorder_model.py, and verified the test cases and reference data updates.
A maintainer makes the merge decision. This review never approves the pull request.
…ression-2-118-0-permane-d3ce Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Stanley Shen <stanleyshen1886@gmail.com>
…ression-2-118-0-permane-d3ce Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Stanley Shen <stanleyshen1886@gmail.com>
Issue resolved by this Pull Request:
Resolves #4151
Relation to #4211
#4211 was opened first and proposes the same two guards for this issue. Pointing out the overlap so reviewers can pick one. Differences visible in its current diff:
_merge_elementsand keeps a hyphen after any token that is not purely alphanumeric. This PR only adds the two rules below and leaves the soft-hyphen and detached-hyphen paths alone (fix(reading-order): keep a detached hyphen when merging elements #4180 is open against the latter).elsevier-00,redp5110_sampledandtable_mislabeled_as_picture, including table structure changes. Here the reference files aremainplus the hyphen deltas only.Description
Since 2.118.0 both sites that close up a word split across a line break drop the hyphen
whenever an alphanumeric character stands on either side of it. A hyphen that is genuinely
part of the word is destroyed with no way to recover it downstream:
noctanal,ntridecanal,ibutyricn-octanal,n-tridecanal,i-butyricpages 1513715145pages 15137-15145xcoordinatex-coordinateTwo shapes of line-final hyphen cannot have been produced by hyphenation, independent of
the document:
behind, so
n-/octanalis a chemical prefix, not a split word.6-methyl-/5-hepten-2-oneisa locant, and
COVID-/19is not a hyphenation point either.Both are now kept, at both join sites. This deliberately leaves out the attested-form
lookup suggested in the issue comments: that needs the whole document available at the
point of the decision, which neither site has.
Changes
PageAssembleModel.sanitize_text: two more conditions on the existing join test, one perrule above.
ReadingOrderModel._merge_elements: the same two rules, so the two join sites agree, andthe kept hyphen is closed up against the lstripped continuation, so
6-methyl-+5-hepten-2-onegives
6-methyl-5-hepten-2-one.2203.01017v2,2206.01062and2305.03393v1regenerated, and a one-line change to main'snewspaper-00reference.Reference data
Every difference in the reference data restores a hyphen. The only other changes are the
provenance charspans that grow by the one recovered character:
pages 1162-1167,pages 65-72,pages 15137-15145,pp. 545-561,pp. 1868-1873x-coordinatenewspaper-00:Anna Hug, nftbecomesAnna Hug, n-ft(single-character token before the hyphen), charspan 218 -> 219The data was generated with
DOCLING_GEN_TEST_DATA=1 uv run pytestand then reduced tothe hyphen differences, because a full local regeneration also picks up layout-model
differences between this machine and CI (element splitting and bounding boxes in
2203.01017v2and2305.03393v1) that have nothing to do with this change. Againstmainthe committed files are therefore
mainplus the hyphen deltas only.Testing
tests/test_page_assemble_model.py::TestSanitizeTextHyphenation::test_attached_hyphen_belonging_to_word_is_keptand the new rows in
tests/test_readingorder_hyphenated_merges.pyfail onmainandpass with this change (6 failures before, all green after).
uv run pytest tests/test_page_assemble_model.py tests/test_readingorder_hyphenated_merges.py: 52 passed.tests/data/pdf/sources/newspaper-00.pdfon this branch producesn-ft, matching the updated reference line.uv run pytest tests/test_e2e_conversion.py:2206.01062.pdfpasses all three checkslocally.
2203.01017v2.pdfand2305.03393v1.pdffail identically onmainand on thisbranch in this environment, from the layout differences noted above, so CI is the place to
confirm them.
make check: ruff and ty pass. The max-lines check fails only on files this PR does not touch.Checklist:
🤖 Generated with Claude Code