| |
| import json |
| from pathlib import Path |
| from jsonschema import Draft202012Validator |
|
|
| ROOT = Path(__file__).resolve().parents[1] |
| schema = json.loads((ROOT / "schemas" / "record.schema.json").read_text(encoding="utf-8")) |
| validator = Draft202012Validator(schema) |
|
|
| errors = [] |
| count = 0 |
| for split in ("train", "validation", "test"): |
| with (ROOT / "data" / f"{split}.jsonl").open(encoding="utf-8") as f: |
| for line_number, line in enumerate(f, 1): |
| count += 1 |
| record = json.loads(line) |
| for error in validator.iter_errors(record): |
| errors.append((split, line_number, record.get("id"), error.message)) |
|
|
| print(f"Validated records: {count}") |
| print(f"Schema errors: {len(errors)}") |
| for item in errors[:20]: |
| print(item) |
|
|
| raise SystemExit(1 if errors else 0) |
|
|