| import json |
| import os |
| import sys |
|
|
|
|
| def extract(instance_id, base_dir="converted_data/java"): |
| |
| if "-" not in instance_id: |
| print(f"Invalid instance_id format: '{instance_id}', expected org__repo-number") |
| sys.exit(1) |
|
|
| prefix, number = instance_id.rsplit("-", 1) |
| org, repo = prefix.split("__") |
| filename = f"{org}__{repo}_dataset.jsonl" |
| filepath = os.path.join(base_dir, filename) |
|
|
| if not os.path.exists(filepath): |
| print(f"File not found: {filepath}") |
| sys.exit(1) |
|
|
| with open(filepath) as f: |
| for line in f: |
| record = json.loads(line) |
| if str(record.get("number")) == number: |
| output_file = os.path.join(base_dir, f"{org}__{repo}_dataset_{instance_id}.jsonl") |
| with open(output_file, "w") as out: |
| out.write(json.dumps(record, ensure_ascii=False, indent=2) + "\n") |
| print(f"Saved to {output_file}") |
| return |
|
|
| print(f"instance_id '{instance_id}' not found in {filepath}") |
|
|
|
|
| if __name__ == "__main__": |
| if len(sys.argv) != 2: |
| print(f"Usage: {sys.argv[0]} <instance_id>") |
| sys.exit(1) |
| extract(sys.argv[1]) |
|
|