Fix PDF text ordering in ScenarioList.from_pdf#2384
Open
Swapnil-jain wants to merge 1 commit intoexpectedparrot:mainfrom
Open
Fix PDF text ordering in ScenarioList.from_pdf#2384Swapnil-jain wants to merge 1 commit intoexpectedparrot:mainfrom
Swapnil-jain wants to merge 1 commit intoexpectedparrot:mainfrom
Conversation
PdfTools.extract_text_from_pdf was using page.get_text() which returns
text in arbitrary order. Updated to use get_text("blocks") and sort
blocks by vertical then horizontal position, matching the behavior of
Scenario.from_pdf via PdfExtractor.
Author
|
A review please @johnjosephhorton @rbyh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ScenarioList.from_pdf()is dropping/misordering content that loads fine withScenario.from_pdf()#957ScenarioList.from_pdf()now extracts text in proper reading order, matchingScenario.from_pdf()behaviorReasoning
PdfTools.extract_text_from_pdf()was usingpage.get_text()which returns text blocks in arbitrary order determined by the PDF's internal structure. This caused content to appear misordered (e.g., question texts out of order with options).Scenario.from_pdf()usesPdfExtractorwhich extracts text blocks viaget_text("blocks")and sorts them by vertical position (y0) then horizontal position (x0) to maintain proper reading order.Updated
PdfTools.extract_text_from_pdf()to use the same block-based extraction and sorting approach.