PDF: line-final hyphen is removed before a capitalized word (non-Hodgkin becomes nonHodgkin)
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 25/100
Research direction
Read PageAssembleModel.sanitize_text in docling/models/stages/page_assemble/page_assemble_model.py and the regression cases in tests/test_page_assemble_model.py. Run those tests to check the lowercase-before-capital case and the mixed-case and uppercase cases. The issue describes the expected output; an open linked pull request (#5593) already covers this work.
Written by the indexing model from the issue text.
Description
Summary
When a PDF line ends with a hyphen after a lowercase word and the next line starts with a capital letter, PageAssembleModel.sanitize_text deletes the hyphen and joins the two halves. Compounds with a proper noun or acronym become wrong words: "non-Hodgkin lymphoma" becomes "nonHodgkin lymphoma", "anti-American" becomes "antiAmerican", "pre-COVID" becomes "preCOVID".
Users cannot get the hyphen back from the output, and a search for the correct term fails. This is the same class of problem as #4151 and #5492. ReadingOrderModel._merge_elements already joins across clusters only when the continuation is lowercase, so the two places now disagree.
Reproduction
Run on current main (0521b433):
from docling.models.stages.page_assemble.page_assemble_model import PageAssembleModel, PageAssembleOptions
m = PageAssembleModel(PageAssembleOptions())
for lines in (["patients with non-", "Hodgkin lymphoma"], ["the anti-", "American campaign"],
["before the pre-", "COVID period"], ["new algo-", "rithms"], ["the INFOR-", "MATION"]):
print(lines, "->", repr(m.sanitize_text(list(lines))))
Actual
['patients with non-', 'Hodgkin lymphoma'] -> 'patients with nonHodgkin lymphoma'
['the anti-', 'American campaign'] -> 'the antiAmerican campaign'
['before the pre-', 'COVID period'] -> 'before the preCOVID period'
['new algo-', 'rithms'] -> 'new algorithms'
['the INFOR-', 'MATION'] -> 'the INFORMATION'
Expected
'patients with non-Hodgkin lymphoma'
'the anti-American campaign'
'before the pre-COVID period'
'new algorithms' (unchanged)
'the INFORMATION' (unchanged)
Cause
sanitize_text keeps an attached line-final hyphen only for a few special cases (a single-character token, a digit continuation, an uppercase abbreviation before a lowercase continuation, from #4387 and #5498). In every other case it removes the hyphen and joins. A hyphenation break almost never puts a capital letter after an all-lowercase word, but this case is not handled.
Proposed fix
Add one more keep-rule: the whole word before the hyphen is lowercase and the continuation starts with an uppercase letter. The rule is deliberately narrow. A mixed-case word split before a capital, such as TeX breaking "Table-|Former", "PubTab-|Net" or "Java-|Script" (these breaks occur in docling's own test PDFs 2203.01017v2 and 2305.03393v1), still joins into "TableFormer" / "JavaScript". "algo-|rithms" and "INFOR-|MATION" behave as now.
There are regression tests (positive and negative) in tests/test_page_assemble_model.py. I scanned the CI PDF sources: the only breaks that match the narrow rule are artifacts from text in different columns, and none of them is joined in the groundtruth, so no e2e groundtruth should change. I could not run the e2e conversion locally (no models), so CI should confirm this.
I used an AI coding assistant (Claude) to find and analyse this; I reproduced it and checked the fix myself.
I've tested a fix with a regression test: https://github.com/chaitanya0305/docling/compare/main...chaitanya0305:docling:fix/keep-hyphen-before-capitalized. If this is accepted, I'll open the PR straight away.
- Dominant language
- Python
- Stars
- 71k
- Forks
- 5.4k
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 161
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from docling-project/docling
-
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
docling-project/docling#5592 ·
Maintainers usually reply within 2 days
-
`api_image_request` logs and propagates the raw error response body, leaking the request's API key on 401Possibly taken @prassu017 claimed this 7 days ago. Openbug priority:critical
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
docling-project/docling#5486 · 1 comment · 1 reaction ·
Maintainers usually reply within 2 days
-
AFP: export_to_doctags() raises ZeroDivisionError because every page has size 0x0Possibly taken @Krushil-Dhankecha claimed this 12 days ago. Openbug priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
docling-project/docling#5355 · 1 comment ·
Maintainers usually reply within 2 days
-
AsciiDoc: thematic breaks and page breaks are kept as text or turned into list itemsPossibly taken @sohailshk claimed this 12 days ago. Openasciidoc bug priority:low
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
docling-project/docling#5331 · 1 comment ·
Maintainers usually reply within 2 days
-
Merged paragraph across pages of different heights: continuation bbox uses the first page's heightPossibly taken @galer1us claimed this 15 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
docling-project/docling#5286 ·
Maintainers usually reply within 2 days
All issues in docling-project/docling
Similar issues
-
Task select patterns with uppercase letters never matchPossibly taken @manobhisriram claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
app: scripts status: backlog type: housekeeping
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
netbox-community/netbox-scripts#239 ·
Maintainers usually reply within 1 day
-
Lambda deploys fail once the bundle grows by about 254 KBPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
developmentseed/titiler-cmr#341 ·
Maintainers usually reply within 1 day
-
Card tables add "..." to every value in a DataFrame column when any value is longer than 30 charactersPossibly taken @omkarbandikatte claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day