2022-03-22 12:54:10 +01:00

29 lines
959 B
Python

from os.path import join
import json
from vidocp.table_parsing import parse_table
from vidocp.locations import TEST_DATA_DIR
from vidocp.test.config import TEST_CONFIG
from vidocp.utils.test_metrics import compute_document_score
from vidocp.utils.preprocessing import open_pdf
def test_figures():
files = [f"file{i}" for i in range(1, 11)]
print(files)
for file in files:
cfg = TEST_CONFIG[file]
print("cfg:", cfg)
json_path = join(TEST_DATA_DIR, cfg.annotation)
with open(json_path) as f:
annotation = json.load(f)["tables"]
print(annotation)
pdf = open_pdf(join(TEST_DATA_DIR, cfg.name))[0]
# result = parse_table(pdf)["result"]["figures"]
result = {}
for n, page in enumerate(pdf):
tables = parse_table(page)
if tables:
result.update({str(n): tables})
assert compute_document_score(annotation, result) >= 0.8