Merged
Conversation
Contributor
Author
|
Please note that this fix isn't perfect. For RTL langauges, for example, you might do a subsequent PR like this: def _get_text_direction(self, par):
"""Get the text direction of the paragraph.
Arabic, Hebrew, Persian, are right-to-left languages.
When the paragraph element is None, attempts to infer direction from
other paragraphs in the document, defaulting to left-to-right.
"""
if par is None:
# Try to infer from other paragraphs in the document
for p in self.hocr.iterfind(self._child_xpath('p', 'ocr_par')):
if p is not None and p.attrib.get('dir') == 'rtl':
return TextDirection.RTL
return TextDirection.LTR
return (
TextDirection.RTL
if par.attrib.get('dir', 'ltr') == 'rtl'
else TextDirection.LTR
)However, this PR should resolve a vast majority of the issues. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1493 +/- ##
==========================================
- Coverage 90.14% 90.11% -0.03%
==========================================
Files 95 95
Lines 7133 7135 +2
Branches 728 729 +1
==========================================
Hits 6430 6430
- Misses 497 498 +1
- Partials 206 207 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
Anyone going to review this? |
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.
Fix AttributeError in HocrTransform._get_text_direction when par is None
When processing certain HOCR files, the
_get_text_directionmethod can receive aNonevalue for itsparparameter. This occurs when either:<p class='ocr_par'>)self.hocr.find(...)returnsNoneWithout a check for this condition, the method attempts to access
par.attribon aNoneobject, resulting in anAttributeError:The Fix
This PR adds a simple null check to handle the case where
parisNone, returning the default left-to-right text direction instead of crashing.This change:
Example File - error occurring when processing Page 115
DivXGuide51.pdf