Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(text-extract): Add fix and test for recap-> op #193

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions doctor/lib/text_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def get_page_text(page: pdfplumber.PDF.pages, strip_margin: bool) -> str:
:param strip_margin: a flag to crop out the margin of a document and skewed content
:return: Text from the pdf plumber page
"""
if strip_margin:
_, _, width, height = page.bbox
if strip_margin and (height > width):
# Crop margins and remove skewed text
_, _, width, height = page.bbox
pixels_per_inch = width / 8.5
bbox = (
0,
Expand All @@ -57,7 +57,10 @@ def get_page_text(page: pdfplumber.PDF.pages, strip_margin: bool) -> str:
page.crop(bbox)
.filter(is_skewed)
.extract_text(
layout=True, keep_blank_chars=True, y_tolerance=5, y_density=25
layout=True,
keep_blank_chars=True,
y_tolerance=5,
y_density=25,
)
)
else:
Expand Down
Binary file not shown.
20 changes: 20 additions & 0 deletions doctor/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ def test_recap_extraction_with_strip_margin(self):
msg="Wrong Text",
)

def test_recap_strip_marign_with_multiple_shaped_pdfs(self):
"""Can we extract atypical shape pdf with strip margin?"""

files = make_file(
filename="recap_extract/gov.uscourts.azd.1085839.3.0.pdf"
)
params = {"strip_margin": True}
response = requests.post(
"http://doctor:5050/extract/recap/text/",
files=files,
params=params,
)
first_line = response.json()["content"].splitlines()[0].strip()
self.assertEqual(200, response.status_code, msg="Wrong status code")
self.assertEqual(
"1 WO",
first_line,
msg="Wrong Text",
)

def test_strip_margin_without_ocr(self):
"""Can we extract from the new recap text endpoint with strip margin?"""
files = make_file(
Expand Down
Loading