Repository navigation
fix(sanitizer): fold curly double quotes to ", not ' - #349
Conversation
|
✅ DCO Check Passed Thanks @wittjeff, all your commits are properly signed off. 🎉 |
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/
|
|
Following up on the groundtruth question from the description now that I can reach the corpus. I ran
The regression job on this PR has not run yet: the "Run CI" workflow run is sitting in For the groundtruth update: I can regenerate the affected pages with Affected pages (77 documents, 148 pages) |
|
Dataset groundtruth PR for the 148 pages above, regenerated on 4eaebf4 and verified by hash to touch nothing else: https://huggingface.co/datasets/docling-project/regression-dataset-for-docling-parse/discussions/5 Note for sequencing: |
`text_constants::replacements` folds the whole U+2018..U+201F quote block to ASCII before any text leaves the parser, and mapped the four double quotes U+201C, U+201D, U+201E, U+201F to `'` alongside the single quotes. That changes meaning: `24” x 36”` (inches) came out as `24' x 36'` (feet), and since the exported `orig` field is a copy of the folded text, nothing downstream could recover the original character. The table dates to docling-project#94, which gives no reason for folding double quotes to an apostrophe; docling's own `PageAssembleModel.sanitize_text` already maps them to `"`. Map the four double quotes to `"`. The single-quote entries and U+201A -> `,` are unchanged. `tests/test_unit_quote_sanitization.py` builds the pages in memory: core-14 Helvetica with /WinAnsiEncoding for the codes WinAnsi has (0x91..0x94, 0x84), and an Identity-H font with a /ToUnicode bfrange for the whole block, so U+201B and U+201F are covered too. Fixes docling-project#335. Root cause of docling-project/docling#1433. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X7AdKLZDGfNTS2LJGmhehR Signed-off-by: Jeff Witt <1848307+wittjeff@users.noreply.github.com>
4eaebf4 to
95d24e3
Compare
|
Rebased onto https://huggingface.co/datasets/docling-project/regression-dataset-for-docling-parse/discussions/6 588 files, 147 pages in 76 documents. Verified file by file rather than by hash alone: the One page fewer than the list above: Also noticed while diffing: dataset main carries 753 |
Summary
The cell text sanitizer folds the U+2018..U+201F quote block to ASCII before any text leaves the parser, and mapped the four double quotes
“ ” „ ‟(U+201C, U+201D, U+201E, U+201F) to'alongside the single quotes. That changes meaning:24” x 36”(inches) came out as24' x 36'(feet). The fold runs outside thedo_sanitizationflag and the exportedorigfield is a copy of the folded text, so nothing downstream could recover the character.Fixes #335. Also the root cause of docling-project/docling#1433 (Apr 2025), where the parser was identified but no docling-parse issue was opened.
Cause
text_constants::replacementsinsrc/parse/pdf_sanitators/constants.h. The whole block dates to #94, which gives no reason for folding double quotes to an apostrophe. docling's ownPageAssembleModel.sanitize_textalready maps“ ”to", so the parser was the layer out of step with its consumer.Change
Map U+201C, U+201D, U+201E, U+201F to
". The single-quote entries (U+2018, U+2019, U+201B to') and U+201A to,are unchanged. Four lines.Test
tests/test_unit_quote_sanitization.py, self-contained viatests/pdf_builder.py:/WinAnsiEncodingand no embedded program, setting 0x91..0x94 and 0x84 (quoteleft, quoteright, quotedblleft, quotedblright, quotedblbase), so the glyph decode is not in question;/ToUnicodebfrange covers the whole block, so U+201B and U+201F are exercised too;orig == textcheck.Against 7.19.0 the WinAnsi tests fail with
["24' x 36'"] == ['24" x 36"']; with the change all five pass and the 169 existingtest_unit_*tests are unaffected.The issue's own repro, after the change:
Regression groundtruth
Not regenerated here: the HF corpus was unreachable from my environment. Pages whose source PDFs contain curly double quotes will change
'to"in their cell text; at most 26 of the 110 parser groundtruth pages contain a'at all. Happy to push the dataset update once CI shows the affected set, or leave it to whoever normally bumpsHF_DATASET_REVISION.Downstream, a docling-parse bump carrying this will shift docling's PDF groundtruth in the same way.
🤖 Generated with Claude Code
https://claude.ai/code/session_01X7AdKLZDGfNTS2LJGmhehR