forked from SVAIGBA/TwASP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_syninfo.py
56 lines (43 loc) · 2.02 KB
/
get_syninfo.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
49
50
51
52
53
54
from twasp_helper import request_features_from_stanford, request_features_from_berkeley
import argparse
import os
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--dataset",
default=None,
type=str,
required=True,
help="The dataset. Should be one of \'CTB5\', \'CTB6\', \'CTB7\', \'CTB9\', "
"\'UD1\' and \'UD2\'.")
parser.add_argument("--toolkit",
default=None,
type=str,
required=True,
help="The toolkit to be used. Should be one of \'SCT\' and \'BNP\'.")
parser.add_argument("--overwrite",
action='store_true',
help="Whether to overwrite existing data.")
args = parser.parse_args()
print(vars(args))
input_dir = os.path.join('./data/', args.dataset)
if args.overwrite:
print('All existing files will be overwrote')
for flag in ['train', 'dev', 'test']:
input_file = os.path.join(input_dir, flag + '.tsv')
if not os.path.exists(input_file):
print('File does not exits: %s' % str(input_file))
continue
if args.toolkit == 'SCT':
out_file = os.path.join(input_dir, flag + '.stanford.json')
if os.path.exists(out_file) and not args.overwrite:
print('File already exists: %s' % str(out_file))
continue
request_features_from_stanford(input_file)
elif args.toolkit == 'BNP':
out_file = os.path.join(input_dir, flag + '.berkeley.json')
if os.path.exists(out_file) and not args.overwrite:
print('File already exists: %s' % str(out_file))
continue
request_features_from_berkeley(input_file)
else:
raise ValueError('Invalid type of toolkit name: %s. Should be one of \'SCT\' and \'BNP\'.' % args.toolkit)