Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
t_rex / process.py
asahi417's picture
init
7fe48b5
raw
history blame
994 Bytes
"""
wget https://figshare.com/ndownloader/files/8760241
unzip 8760241
"""
import json
import os
from glob import glob
from tqdm import tqdm
# from random import shuffle, seed
os.makedirs('data', exist_ok=True)
f_writer = open('data/t_rex.raw.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")
f_writer.close()
with open('data/t_rex.raw.jsonl') as f:
data = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
s = {i['subject'] for i in data}
o = {i['object'] for i in data}
s.update(o)