| import json | |
| from pathlib import Path | |
| KEEP_KEYS = {"id", "nb", "nn"} | |
| input_dir = Path(".") | |
| output_dir = Path("cleaned_minimal") | |
| output_dir.mkdir(exist_ok=True) | |
| for path in input_dir.glob("*.jsonl"): | |
| out_path = output_dir / path.name | |
| with path.open("r", encoding="utf-8") as fin, out_path.open("w", encoding="utf-8") as fout: | |
| for line in fin: | |
| obj = json.loads(line) | |
| filtered = {k: v for k, v in obj.items() if k in KEEP_KEYS} | |
| fout.write(json.dumps(filtered, ensure_ascii=False) + "\n") | |
| print(f"[✓] Stripped {path.name}") | |