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])) | |