forked from ThiagoCF05/NeuralREG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_samples_from_trials.py
47 lines (36 loc) · 2.25 KB
/
generate_samples_from_trials.py
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
39
40
41
42
43
44
45
46
47
__author__ = 'thiagocastroferreira'
import json
import os
from random import shuffle
if __name__ == '__main__':
with open('trials/beta/sample-ids.txt', encoding='utf-8') as f:
ids = f.read().split('\n')
entries = json.load(open(os.path.join('trials/beta', 'trials_b.json'), encoding='utf-8'))
source, texts = [], []
for i in ids:
e = [w for w in entries if w['eid'] == i][0]
# for e in entries:
texts.append(
"{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}".format(e['eid'], e['lid'], e['category'], e['size'], 'only', e['only'],
e['source']).replace('<TRIPLE> ', '').replace('</TRIPLE>',
'.'))
texts.append(
"{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}".format(e['eid'], e['lid'], e['category'], e['size'], 'attacl', e['attacl'],
e['source']).replace('<TRIPLE> ', '').replace('</TRIPLE>',
'.'))
texts.append(
"{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}".format(e['eid'], e['lid'], e['category'], e['size'], 'attcopy', e['attcopy'],
e['source']).replace('<TRIPLE> ', '').replace('</TRIPLE>',
'.'))
texts.append("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}".format(e['eid'], e['lid'], e['category'], e['size'], 'profilereg',
e['profilereg'], e['source']).replace('<TRIPLE> ', '').replace('</TRIPLE>',
'.'))
with open(os.path.join('trials/beta', 'samples_b_ordered.csv'), 'w') as f:
f.write('eid\tlid\tcategory\tsize\tmodel\ttext\tsource\n')
for e in texts:
f.write(e + '\n')
shuffle(texts)
with open(os.path.join('trials/beta', 'samples_b.csv'), 'w') as f:
f.write('eid\tlid\tcategory\tsize\tmodel\ttext\tsource\n')
for e in texts:
f.write(e + '\n')