Repository navigation
Fix: parse negative coordinates in @@ position tags - #19945
Conversation
The posTagPattern regex used a coordinate class of [0-9.\t]+, which cannot match a leading minus sign. Any position tag with a negative coordinate (e.g. a content box extending slightly above the page top, top=-3.0) failed to parse, so ExtractPositions returned an empty list and CropSectionImage silently dropped the section image with the 'cropSectionImage: empty position list' warning. Negative coordinates are legitimate (a box can overflow the page origin); CropSectionImage already clamps out-of-bounds values via FastCrop. Allow '-' in the coordinate class so such tags parse and the section image is generated instead of being lost. This is a Go-side fix. The Python parser (deepdoc/parser/pdf_parser.py) uses the same regex and has the same latent bug; a separate issue should track syncing it. Co-authored-by: CodeBuddy <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe PDF position parser now accepts negative coordinates. Tests cover extraction, formatting roundtrips, and image cropping for a slightly negative top coordinate. ChangesNegative Position Coordinates
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~15 minutes Change: Bug fix 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit finds a minus sign bright Comment |
…ython side Sync the Python readers with the Go-side fix in infiniflow#19945, whose notes call out this exact gap: the coordinate class [0-9.\t]+ cannot match a leading minus, so tags like @@50<TAB>45.0<TAB>549.7<TAB>-3.0<TAB>737.9## produced by Pdf._line_tag (top is offset by page_cum_height and can go negative) were dropped by extract_positions (empty position list -> section image silently lost) and left un-stripped by the chunk tokenizer, leaking raw tags into chunk text. Allow '-' in the coordinate class at all nine read sites, keeping reader and writer self-consistent. Add regression tests driving the real RAGFlowPdfParser.extract_positions and remove_tag with negative coordinates and page-range tags.
Summary
posTagPatternregex ininternal/deepdoc/parser/pdf/util/position.goused a coordinate class of[0-9.\t]+, which cannot match a leading minus sign. Any position tag with a negative coordinate (e.g. a content box extending slightly above the page top,top=-3.0) failed to parse.ExtractPositionsreturned an empty list andCropSectionImagesilently dropped the section image with thecropSectionImage: empty position listwarning — the section lost its cropped image in the QA/retrieval UI.CropSectionImagealready clamps out-of-bounds values viaFastCrop. The fix allows-in the coordinate class so such tags parse and the section image is generated.Root cause
Reported warning:
The tag's
top=-3.0is negative.FormatPositionTagwrites it verbatim, butExtractPositions' regex rejected it — a writer/reader self-inconsistency. Each affected section failed in both theCropSectionPositionspath and the directCropSectionImagefallback, which is why the warning appeared twice per tag.Test plan
TestExtractPositionsNegativeCoordandTestFormatPositionTagNegativeRoundtrip(position_test.go) plusTestCropSectionImage_NegativeCoordNotDropped(crop_test.go) covering negative coords and the format/parse roundtrip.bash build.sh --test ./internal/deepdoc/parser/pdf/util/and./internal/parser/parser/both pass; no regression.Notes
deepdoc/parser/pdf_parser.py:1941) uses the same regex and has the same latent bug; a separate issue should track syncing it (out of scope per current phase constraints).