File size: 678 Bytes
6d1a3ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import json

qrel_filenames = [
    "qrels.dl21-doc-msmarco-v2.1.txt",
    "qrels.msmarco-v2.1-doc.dev.txt",
    "qrels.dl22-doc-msmarco-v2.1.txt",
    "qrels.msmarco-v2.1-doc.dev2.txt",
    "qrels.dl23-doc-msmarco-v2.1.txt",
    "qrels.rag24.raggy-dev.txt",
]
for filename in qrel_filenames:
    short_filename = filename.split("qrels.")[1][:-4]
    qrels: dict = {}
    with open(filename, "r") as f:
        for line in f:
            qid, _, doc_id, label = line.strip().split()
            if qid not in qrels:
                qrels[qid] = {}
            qrels[qid][doc_id] = int(label)
    with open(f"{short_filename}.json", "w") as w:
        w.write(json.dumps(qrels))