File size: 4,279 Bytes
b6f0739
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
"""Strict, reproducible checks for the 100 manually reviewed semantic records."""

from __future__ import annotations

import argparse
import json
from collections import Counter
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
ANN = ROOT / "annotations"
EXPECTED = {f"CBX100_{index:04d}" for index in range(1, 101)}


def read_jsonl(path: Path) -> list[dict]:
    with path.open(encoding="utf-8") as handle:
        return [json.loads(line) for line in handle if line.strip()]


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("--integrated", action="store_true", help="also verify metadata/prompt synchronization")
    args = parser.parse_args()

    rows = read_jsonl(ANN / "visual_semantics.jsonl")
    ids = [row.get("sample_id") for row in rows]
    errors: list[str] = []
    if len(rows) != 100:
        errors.append(f"expected 100 rows, found {len(rows)}")
    if len(set(ids)) != len(ids):
        errors.append("duplicate sample IDs: " + str([item for item, count in Counter(ids).items() if count > 1]))
    if set(ids) != EXPECTED:
        errors.append(f"ID mismatch; missing={sorted(EXPECTED-set(ids))}, extra={sorted(set(ids)-EXPECTED)}")

    required = {
        "sample_id", "annotation_method", "primary_form", "visual_features",
        "visual_caption_en", "visual_caption_zh", "feature_tree_hint", "confidence",
    }
    feature_keys = {"openings", "recesses", "protrusions", "repeated_structures", "symmetry", "surface_character"}
    for row in rows:
        sid = row.get("sample_id", "<missing>")
        missing = required - row.keys()
        if missing:
            errors.append(f"{sid}: missing fields {sorted(missing)}")
            continue
        if row["annotation_method"] != "manual_visual_inspection_of_four_view_render":
            errors.append(f"{sid}: invalid annotation method")
        if set(row["visual_features"]) != feature_keys:
            errors.append(f"{sid}: visual_features schema mismatch")
        if not row["visual_caption_en"].strip() or not row["visual_caption_zh"].strip():
            errors.append(f"{sid}: blank caption")
        if len(row["feature_tree_hint"]) < 2:
            errors.append(f"{sid}: insufficient feature-tree hints")
        image = ROOT / "data" / "multiview" / f"{sid}.png"
        if not image.is_file():
            errors.append(f"{sid}: missing reviewed four-view image")

    if len({row["visual_caption_en"] for row in rows}) != 100:
        errors.append("English captions are not unique per sample")
    if len({row["visual_caption_zh"] for row in rows}) != 100:
        errors.append("Chinese captions are not unique per sample")

    if args.integrated:
        metadata = {row["sample_id"]: row for row in read_jsonl(ANN / "metadata_extended.jsonl")}
        prompts = {row["sample_id"]: row for row in read_jsonl(ANN / "prompts.jsonl")}
        if set(metadata) != EXPECTED or set(prompts) != EXPECTED:
            errors.append("integrated index IDs do not match the 100-sample set")
        for visual in rows:
            sid = visual["sample_id"]
            if sid not in metadata or sid not in prompts:
                continue
            if metadata[sid]["descriptions"]["en"] != visual["visual_caption_en"]:
                errors.append(f"{sid}: metadata English description is not synchronized")
            if prompts[sid]["descriptions"]["zh"] != visual["visual_caption_zh"]:
                errors.append(f"{sid}: prompt-index Chinese description is not synchronized")
            if metadata[sid]["prompts"] != prompts[sid]["prompts"]:
                errors.append(f"{sid}: prompt payloads are not synchronized")

    if errors:
        print("Visual-semantic validation: FAILED")
        for error in errors:
            print("-", error)
        raise SystemExit(1)

    print("Visual-semantic validation: PASSED")
    print("- 100/100 sample IDs present and unique")
    print("- 100/100 four-view images present")
    print("- 100/100 English and Chinese captions are sample-specific")
    print("- structured features and feature-tree hints complete")
    if args.integrated:
        print("- metadata and prompt indexes synchronized")


if __name__ == "__main__":
    main()