-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_samples.py
48 lines (38 loc) · 1.02 KB
/
print_samples.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
48
import sys
import json
def main():
annotations = [a.lower() for a in sys.argv[1:]]
if len(annotations) == 0:
print("""
Usage:
# python print_samples.py type1 type2 type3 ...
e.g.
# python print_samples.py a c
for all chiasmi and antimetaboles
""")
exit()
with open('data/data.json', 'r') as f:
data = json.load(f)
count = 0
for d in data:
if not d["annotation"].lower() in annotations:
continue
count += 1
print('###', count)
print(to_string(d))
print("###")
print("\n\n\n")
def to_string(sample):
#print(type(sample['tokens'][0]))
#tokens = [t.encode('ascii', 'ignore') for t in sample['tokens']]
tokens = sample['tokens']
ids = [s -sample['cont_ids'][0] for s in sample['ids']]
print(type(tokens[0]))
t_return = []
for i, t in enumerate(tokens):
if i in ids:
t = "["+t+"]"
t_return.append(t)
return " ".join(t_return)
if __name__ == "__main__":
main()