|
""" |
|
wget https://figshare.com/ndownloader/files/8760241 |
|
unzip 8760241 |
|
""" |
|
|
|
import json |
|
import os |
|
from glob import glob |
|
from tqdm import tqdm |
|
|
|
os.makedirs('data', exist_ok=True) |
|
f_writer = open('data/t_rex_clean.jsonl', 'w') |
|
for i in tqdm(glob("*.json")): |
|
with open(i) as f: |
|
data = json.load(f) |
|
for _data in data: |
|
for triple in _data['triples']: |
|
p = triple['predicate']['surfaceform'] |
|
o = triple['object']['surfaceform'] |
|
s = triple['subject']['surfaceform'] |
|
if p is None or o is None or s is None: |
|
continue |
|
out = {"predicate": p, "object": o, "subject": s, "title": _data["title"], "text": _data["text"]} |
|
f_writer.write(json.dumps(out) + "\n") |
|
|