MCPcopy Create free account
hub / github.com/docling-project/docling-parse / test_annotations_match_groundtruth

Function test_annotations_match_groundtruth

tests/test_parse.py:1045–1089  ·  view source on GitHub ↗

Test that annotations match parser groundtruth.

()

Source from the content-addressed store, hash-verified

1043
1044
1045def test_annotations_match_groundtruth():
1046 """Test that annotations match parser groundtruth."""
1047 parser = DoclingPdfParser(loglevel="fatal")
1048
1049 # Test a few PDFs that have groundtruth with annotations
1050 test_files = [
1051 "form_fields.pdf",
1052 "table_of_contents_01.pdf",
1053 ]
1054
1055 for pdf_file in test_files:
1056 pdf_path = f"tests/data/regression/{pdf_file}"
1057 groundtruth_path = PARSER_GROUNDTRUTH_DIR / f"{pdf_file}.json"
1058
1059 if not os.path.exists(pdf_path) or not os.path.exists(groundtruth_path):
1060 continue
1061
1062 # Load document
1063 pdf_doc = parser.load(path_or_stream=pdf_path, lazy=True)
1064 pred_annotations = pdf_doc.get_annotations()
1065
1066 # Load groundtruth
1067 with open(groundtruth_path) as fr:
1068 true_doc = json.load(fr)
1069 true_annotations = true_doc["annotations"]
1070
1071 # Convert PdfAnnotations to dict for comparison
1072 pred_dict = {
1073 "form": pred_annotations.form,
1074 "language": pred_annotations.language,
1075 "meta_xml": pred_annotations.meta_xml,
1076 "table_of_contents": (
1077 None
1078 if pred_annotations.table_of_contents is None
1079 else [
1080 entry.model_dump(exclude_none=True)
1081 for entry in pred_annotations.table_of_contents
1082 ]
1083 ),
1084 }
1085
1086 # Verify match
1087 verify_annotations_recursive(true_annotations, pred_dict)
1088
1089 pdf_doc.unload()
1090
1091
1092BITMAP_PDF = "tests/data/regression/annots_01.pdf"

Callers

nothing calls this directly

Calls 6

loadMethod · 0.95
DoclingPdfParserClass · 0.90
get_annotationsMethod · 0.45
loadMethod · 0.45
unloadMethod · 0.45

Tested by

no test coverage detected