Browse Source

Fix pdfparser content confusion (#1700)

### What problem does this PR solve?

#1407 #1656 

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.9.0
H 1 year ago
parent
commit
b24abee364
No account linked to committer's email address
1 changed files with 2 additions and 16 deletions
  1. 2
    16
      deepdoc/parser/pdf_parser.py

+ 2
- 16
deepdoc/parser/pdf_parser.py View File

"page_number": pagenum} for b, t in bxs if b[0][0] <= b[1][0] and b[0][1] <= b[-1][1]], "page_number": pagenum} for b, t in bxs if b[0][0] <= b[1][0] and b[0][1] <= b[-1][1]],
self.mean_height[-1] / 3 self.mean_height[-1] / 3
) )

# solve char content confusion
record_error_length, ct = 0, 0.001
for c in chars[0:128]:
ii = Recognizer.find_overlapped(c, bxs)
if ii is None:
continue
record_error_length += abs((bxs[ii]["bottom"] + bxs[ii]["top"] - c["bottom"] - c["top"]) / 2)
ct += 1

record_error_length = record_error_length / ct
for char in chars:
char["top"] -= record_error_length
char["bottom"] -= record_error_length
# merge chars in the same rect # merge chars in the same rect
for c in Recognizer.sort_X_firstly(
chars, self.mean_width[pagenum - 1] // 4):
for c in Recognizer.sort_Y_firstly(
chars, self.mean_height[pagenum - 1] // 4):
ii = Recognizer.find_overlapped(c, bxs) ii = Recognizer.find_overlapped(c, bxs)
if ii is None: if ii is None:
self.lefted_chars.append(c) self.lefted_chars.append(c)

Loading…
Cancel
Save