mirror of
https://github.com/lllin000/PaperForge.git
synced 2026-07-22 06:50:53 +00:00
feat(ocr): expand legacy-vnext comparison harness for cutover gates
This commit is contained in:
parent
a431f13a93
commit
7bf4a6d7d4
2 changed files with 52 additions and 6 deletions
|
|
@ -15,7 +15,28 @@ def _figure_asset_ids(fig: dict[str, object]) -> list[str]:
|
|||
return sorted(x for x in ids if x)
|
||||
|
||||
|
||||
def _settlement_type_counts(figures: list[dict]) -> dict[str, int]:
|
||||
counts: dict[str, int] = {}
|
||||
for fig in figures:
|
||||
st = str(fig.get("settlement_type", ""))
|
||||
if st:
|
||||
counts[st] = counts.get(st, 0) + 1
|
||||
return counts
|
||||
|
||||
|
||||
def compare_inventories(legacy: dict[str, object], vnext: dict[str, object]) -> dict[str, object]:
|
||||
_legacy_figure_ids = sorted(
|
||||
str(f.get("figure_id", "")) for f in legacy.get("matched_figures", []) if f.get("figure_id")
|
||||
)
|
||||
_vnext_figure_ids = sorted(
|
||||
str(f.get("figure_id", "")) for f in vnext.get("matched_figures", []) if f.get("figure_id")
|
||||
)
|
||||
_legacy_consumed = sorted(
|
||||
{bid for fig in legacy.get("matched_figures", []) for bid in _figure_asset_ids(fig)}
|
||||
)
|
||||
_vnext_consumed = sorted(
|
||||
{bid for fig in vnext.get("matched_figures", []) for bid in _figure_asset_ids(fig)}
|
||||
)
|
||||
return {
|
||||
"legacy_matched_count": len(legacy.get("matched_figures", [])),
|
||||
"vnext_matched_count": len(vnext.get("matched_figures", [])),
|
||||
|
|
@ -23,12 +44,18 @@ def compare_inventories(legacy: dict[str, object], vnext: dict[str, object]) ->
|
|||
"vnext_unresolved_count": len(vnext.get("unresolved_clusters", [])),
|
||||
"legacy_unmatched_legend_count": len(legacy.get("unmatched_legends", [])),
|
||||
"vnext_unmatched_legend_count": len(vnext.get("unmatched_legends", [])),
|
||||
"legacy_consumed_block_ids": sorted(
|
||||
{bid for fig in legacy.get("matched_figures", []) for bid in _figure_asset_ids(fig)}
|
||||
),
|
||||
"vnext_consumed_block_ids": sorted(
|
||||
{bid for fig in vnext.get("matched_figures", []) for bid in _figure_asset_ids(fig)}
|
||||
),
|
||||
"legacy_consumed_block_ids": sorted(_legacy_consumed),
|
||||
"vnext_consumed_block_ids": sorted(_vnext_consumed),
|
||||
# New gate fields
|
||||
"legacy_completeness": legacy.get("figure_legend_completeness", {}),
|
||||
"vnext_completeness": vnext.get("completeness", {}),
|
||||
"legacy_figure_ids": _legacy_figure_ids,
|
||||
"vnext_figure_ids": _vnext_figure_ids,
|
||||
"vnext_pass_names": [str(r.get("pass_name", "")) for r in vnext.get("pass_reports", [])],
|
||||
"legacy_settlement_types": _settlement_type_counts(legacy.get("matched_figures", [])),
|
||||
"vnext_settlement_types": _settlement_type_counts(vnext.get("matched_figures", [])),
|
||||
"consumed_ids_only_in_legacy": sorted(set(_legacy_consumed) - set(_vnext_consumed)),
|
||||
"consumed_ids_only_in_vnext": sorted(set(_vnext_consumed) - set(_legacy_consumed)),
|
||||
}
|
||||
|
||||
def compare_blocks_file(blocks_path: Path) -> dict[str, object]:
|
||||
|
|
|
|||
|
|
@ -15,3 +15,22 @@ def test_compare_inventories_reports_counts_for_same_page_case():
|
|||
|
||||
assert diff["vnext_matched_count"] >= 1
|
||||
assert "vnext_consumed_block_ids" in diff
|
||||
|
||||
def test_compare_inventories_now_includes_gate_fields():
|
||||
blocks = [
|
||||
{"block_id": "c1", "page": 1, "role": "figure_caption", "text": "Figure 1. Caption", "bbox": [0, 100, 200, 150]},
|
||||
{"block_id": "a1", "page": 1, "role": "figure_asset", "bbox": [0, 0, 200, 90], "raw_label": "image"},
|
||||
]
|
||||
legacy = build_figure_inventory_legacy(blocks, 1200)
|
||||
vnext = build_figure_inventory_vnext(blocks, 1200)
|
||||
diff = compare_inventories(legacy, vnext)
|
||||
|
||||
assert "legacy_completeness" in diff
|
||||
assert "vnext_completeness" in diff
|
||||
assert "legacy_figure_ids" in diff
|
||||
assert "vnext_figure_ids" in diff
|
||||
assert "vnext_pass_names" in diff
|
||||
assert "legacy_settlement_types" in diff
|
||||
assert "vnext_settlement_types" in diff
|
||||
assert "consumed_ids_only_in_legacy" in diff
|
||||
assert "consumed_ids_only_in_vnext" in diff
|
||||
|
|
|
|||
Loading…
Reference in a new issue