File size: 1,472 Bytes
feb1b1c
f405c45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05f0c93
 
f405c45
 
 
 
 
 
05f0c93
f405c45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

import json
from pathlib import Path

# Path definitions anchoring our raw and golden targets
RAW_DATA_PATH = Path("data/raw/candidates.jsonl")
OUTPUT_SAMPLE_PATH = Path("data/raw/sandbox_sample.jsonl")


def build_sandbox_sample() -> None:
    """Extracts a clean, deterministic slice of records for local runs."""
    if not RAW_DATA_PATH.exists():
        print(f"Error: Raw fact dataset missing at {RAW_DATA_PATH}. Aborting script.")
        return

    print(f"Reading raw pool from {RAW_DATA_PATH}...")
    sample_records: list[dict] = []

    # Sandbox sample must stay <=100 candidates (submission spec Sec 10.5).
    with open(RAW_DATA_PATH, "r", encoding="utf-8") as infile:
        for idx, line in enumerate(infile):
            if not line.strip():
                continue
            try:
                record = json.loads(line)
                if len(sample_records) < 100:
                    sample_records.append(record)
                else:
                    break
            except json.JSONDecodeError:
                continue

    OUTPUT_SAMPLE_PATH.parent.mkdir(parents=True, exist_ok=True)
    
    with open(OUTPUT_SAMPLE_PATH, "w", encoding="utf-8") as outfile:
        for record in sample_records:
            outfile.write(json.dumps(record) + "\n")

    print(f"Successfully compiled {len(sample_records)} records into {OUTPUT_SAMPLE_PATH}!")


if __name__ == "__main__":
    build_sandbox_sample()