Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
File size: 1,243 Bytes
7b9e520
 
 
 
 
 
 
 
 
f479237
7b9e520
 
f479237
7b9e520
 
 
 
 
 
 
 
 
 
 
 
f479237
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
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()

seed(0)
with open('data/t_rex.raw.jsonl') as f:
    data = [json.loads(i) for i in f.read().split('\n') if len(i) > 0]
shuffle(data)
train = data[:int(len(data) * 0.7)]
val = data[int(len(data) * 0.7):int(len(data) * 0.85)]
test = data[int(len(data) * 0.85):]
for i, j in zip([train, val, test], ['train', 'validation', 'test']):
    with open(f'data/t_rex.raw.{j}.jsonl', 'w') as f:
        f.write('\n'.join([json.dumps(l) for l in i]))