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))