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

Try to reproduce #12, but can't #433

Closed
wants to merge 1 commit into from
Closed
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
37 changes: 37 additions & 0 deletions tests/parser/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
TextDocPreprocessor,
TSVDocPreprocessor,
)
from fonduer.utils.utils_visual import Bbox


def get_parser_udf(
Expand Down Expand Up @@ -46,6 +47,42 @@ def get_parser_udf(
return parser_udf


def test_visual_linker():
"""Test the visual_linker (#12)."""
docs_path = "tests/data/html_simple/md.html"
pdf_path = "tests/data/pdf_simple/md.pdf"

# Preprocessor for the Docs
preprocessor = HTMLDocPreprocessor(docs_path)
doc = next(preprocessor._parse_file(docs_path, "md"))

# Create an Parser and parse the md document
parser_udf = get_parser_udf(
structural=True,
tabular=True,
lingual=True,
visual=True,
pdf_path=pdf_path,
language="en",
)
doc = parser_udf.apply(doc)

# Check bbox for "One"
sentence = doc.sentences[4]
assert sentence.text == "One"
assert sentence.get_bbox() == Bbox(page=1, left=95, top=155, right=114, bottom=168)

# Check bbox for "Two"
sentence = doc.sentences[5]
assert sentence.text == "Two"
assert sentence.get_bbox() == Bbox(page=1, left=95, top=169, right=116, bottom=182)

# Check bbox for "Three"
sentence = doc.sentences[6]
assert sentence.text == "Three"
assert sentence.get_bbox() == Bbox(page=1, left=95, top=182, right=122, bottom=195)


def test_parse_md_details():
"""Test the parser with the md document."""
logger = logging.getLogger(__name__)
Expand Down