File size: 830 Bytes
b227dc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
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)