File size: 440 Bytes
f63efd0
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
import json
from glob import glob
from itertools import chain

for i in glob("dataset/*.jsonl"):
    with open(i) as f:
        tmp = [json.loads(o) for o in f.read().split('\n') if len(o) > 0]
    for r in tmp:
        r['negatives'] = r['negatives'] + list(
            chain(*[o['positives'] for o in tmp if o['relation_type'] != r['relation_type']]))
    with open(i, 'w') as f:
        f.write('\n'.join([json.dumps(r) for r in tmp]))