-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontrol.py
86 lines (67 loc) · 2.33 KB
/
control.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
import trainPreprocess
import testPreprocess
import trainModel
import testRun
import testAnnotatePreprocess
import sys, getopt
#printing usage for command line options and exit
def printUsage():
print ('----USAGE----')
print ('python control.py -pre_train_skip -train_skip -test_skip -n_train <number>')
sys.exit(2)
#Command Line options for System
def command_line_opts(argv):
#Try if options are present
list = []
#Iterate through list of arguments (Only these arguments would be matched if size of list is <=6
if len(argv) <= 6:
for id, arg in enumerate(argv):
if arg == '-pre_train_skip':
list.append(arg)
elif arg == '-train_skip':
list.append(arg)
elif arg == '-test_skip':
list.append(arg)
elif arg == '-train_n' :
list.append('-train_n')
if str(argv[id+1]).isdigit():
list.append(argv[id+1])
else:
printUsage()
sys.exit(2)
#Return List
return list
#Parse Training_set count
def parse_train_count(options):
if "-train_n" in options:
ind = options.index("-train_n")
number = options[ind+1]
else:
number = -1
return number
def genericLoop(argv):
#*****MAIN CONTROL LOOP FOR THE ML TASK*****
#get Command Line Options
options = command_line_opts(argv)
count = parse_train_count(options)
#Train Preprocess - Parse in .col Format
if "-pre_train_skip" not in options:
trainPreprocess.parseTimeML("data/TE3-Silver-data/TE3-Silver-data")
if "-train_skip" not in options:
list = trainPreprocess.inputCol(count);
#Train Model using Stanford Core-nlp
trainModel.train(list)
if "-test_skip" not in options:
#Preprocess Test Model in .txt format
testPreprocess.preProcess()
#Preprocess Test in .col format
testAnnotatePreprocess.parseTimeML("data/te3-platinum-data")
#run the learnt models on the Test-data
testRun.test()
#-----------MAIN FUNCTION----------
def main(argv):
#****CALL to START CONTROL LOOP****
genericLoop(argv)
if __name__ == '__main__':
main(sys.argv[1:])