Spaces:
Sleeping
Sleeping
Create convert_json_to_csv.py
Browse files- convert_json_to_csv.py +38 -0
convert_json_to_csv.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
# Created by zd302 at 12/01/2025
|
| 4 |
+
import csv
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
def convert_json_to_csv(file_json):
|
| 8 |
+
with open(file_json) as f:
|
| 9 |
+
samples = json.load(f)
|
| 10 |
+
|
| 11 |
+
new_samples = []
|
| 12 |
+
for i, sample in enumerate(samples):
|
| 13 |
+
claim = sample['claim']
|
| 14 |
+
label = sample['pred_label']
|
| 15 |
+
prediction_evidence = ""
|
| 16 |
+
for src_qa in sample['evidence']:
|
| 17 |
+
prediction_evidence += src_qa["question"] + "\t\t\n" + src_qa["answer"] + "\t\t\n\n"
|
| 18 |
+
#
|
| 19 |
+
new_samples.append([i, claim, prediction_evidence, label, 'pred'])
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
with open("submission.csv", mode="w", newline="") as file:
|
| 23 |
+
writer = csv.writer(file)
|
| 24 |
+
writer.writerow(["id", "claim", "evi", "label", "split"]) # Write header
|
| 25 |
+
writer.writerows(new_samples)
|
| 26 |
+
|
| 27 |
+
print("{} have been converted to .csv".format(file_json))
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def main():
|
| 31 |
+
user_submission_file = "prediction.json"
|
| 32 |
+
convert_json_to_csv(user_submission_file)
|
| 33 |
+
|
| 34 |
+
print("hello")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
main()
|