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

Use spaCy v2.3.0 or later to use HocrVisualParser #528

Merged
merged 2 commits into from
Oct 26, 2020
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: 4 additions & 5 deletions src/fonduer/parser/visual_parser/hocr_visual_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ def __init__(
):
"""Initialize a visual parser.

:raises ImportError: an error is raised when spaCy is not 2.2.2 or later.
:raises ImportError: an error is raised when spaCy is not 2.3.0 or later.
"""
if version.parse(spacy.__version__) < version.parse("2.2.2"):
if version.parse(spacy.__version__) < version.parse("2.3.0"):
raise ImportError(
f"You are using spaCy {spacy.__version__},"
f"but it should be 2.2.2 or later."
f"You are using spaCy {spacy.__version__}, "
f"but it should be 2.3.0 or later to use HocrVisualParser."
)
spacy.gold.USE_NEW_ALIGN = True
self.replacements: List[Tuple[Pattern, str]] = []
for (pattern, replace) in replacements:
self.replacements.append((re.compile(pattern, flags=re.UNICODE), replace))
Expand Down
3 changes: 2 additions & 1 deletion tests/data/hocr_simple/121.hocr
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
<span class="ocrx_word" id="word_1_67" title="bbox 358 193 366 201">of</span>
<span class="ocrx_word" id="word_1_68" title="bbox 369 193 384 201">this</span>
<span class="ocrx_word" id="word_1_69" title="bbox 387 193 426 201">Account.</span>
<span class="ocrx_word" id="word_1_70" title="bbox 430 193 453 202">“We,”</span>
<!--Use two single-quotes to see if #527 happens-->
<span class="ocrx_word" id="word_1_70" title="bbox 430 193 453 202">''We,''</span>
<span class="ocrx_word" id="word_1_71" title="bbox 457 193 478 202">“Us,”</span>
<span class="ocrx_word" id="word_1_72" title="bbox 482 193 504 201">“Our”</span>
<span class="ocrx_word" id="word_1_73" title="bbox 508 193 524 201">and</span>
Expand Down