Improve pdfoxide parser with text preprocessing - #27
Conversation
- Add preprocess_text to pdfoxide_parser.py - Handle smashed amounts (e.g. 0.001,000.00) - Handle space-separated amounts - Handle embedded User IDs - Handle inline Date/Description separation - Improve benchmark success rate from 0% to 66.7% Co-authored-by: rager306 <248269686+rager306@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
WalkthroughA new public preprocessing function is added to the pdfoxide_parser module to sanitize extracted PDF text by inserting newlines around key boundaries (amounts, user IDs, date-time markers). This preprocessing step is integrated into the PDF parsing flow to improve downstream text extraction robustness without modifying the parser's signature or return structure. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@pdfparser/pdfoxide_parser.py`:
- Around line 113-116: The fallback empty-string is currently inside the comment
and not applied; change the assignment so doc.extract_text(page_num) is OR'd
with "" before the type-ignore comment (e.g., assign page_text =
doc.extract_text(page_num) or "" # type: ignore[attr-defined]) so page_text is
never None prior to calling preprocess_text(page_text) and concatenating into
all_text; update the statement that sets page_text in pdfoxide_parser.py
accordingly.
🧹 Nitpick comments (2)
pdfparser/pdfoxide_parser.py (2)
39-40: Consider a single-pass approach for chained amounts.Applying the same regex twice works but is fragile for longer chains (4+ amounts). A
re.findall+ rejoin or a more targeted pattern might be more robust.That said, given the 66.7% benchmark improvement, the current approach is pragmatic for the known input patterns.
42-45: Potential false positives on non-amount decimals.The pattern
(\d[\d,]*\.\d{2})will match any 2-decimal-place number, potentially splitting text like "Rate 2.50% applied" incorrectly. If this becomes an issue, consider anchoring to expected contexts or adding negative lookbehind for percentage signs.
| page_text = doc.extract_text(page_num) # type: ignore[attr-defined] or "" | ||
| # Preprocess the page text to fix layout issues | ||
| page_text = preprocess_text(page_text) | ||
| all_text += page_text + "\n" |
There was a problem hiding this comment.
Bug: or "" is inside the comment, not in the expression.
The fallback or "" appears after the # type: ignore comment, making it ineffective. If extract_text returns None, page_text will be None.
While preprocess_text handles None via if not text, this is likely unintentional and could mask issues. The intent seems to be a fallback empty string.
🐛 Proposed fix
- page_text = doc.extract_text(page_num) # type: ignore[attr-defined] or ""
+ page_text = doc.extract_text(page_num) or "" # type: ignore[attr-defined]🤖 Prompt for AI Agents
In `@pdfparser/pdfoxide_parser.py` around lines 113 - 116, The fallback
empty-string is currently inside the comment and not applied; change the
assignment so doc.extract_text(page_num) is OR'd with "" before the type-ignore
comment (e.g., assign page_text = doc.extract_text(page_num) or "" # type:
ignore[attr-defined]) so page_text is never None prior to calling
preprocess_text(page_text) and concatenating into all_text; update the statement
that sets page_text in pdfoxide_parser.py accordingly.
Implemented 'preprocess_text' in 'pdfoxide_parser.py' to handle smashed columns (amounts, user IDs) caused by draw-order text extraction. This fixes parsing failures for pdfoxide on standard bank statements, improving benchmark success rate from 0% to 66.7%.
PR created automatically by Jules for task 7756069123368046916 started by @rager306
Summary by CodeRabbit