File size: 1,238 Bytes
9f6b6fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os
import sys


def extract(instance_id, base_dir="converted_data/java"):
    # instance_id format: {org}__{repo}-{number}
    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])