Mercurial > repos > moba > alvis_rep
comparison simpleprojector2.py @ 5:b8f59e6dcf18 draft
Uploaded
author | moba |
---|---|
date | Tue, 02 May 2017 06:05:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:f64cd17140fe | 5:b8f59e6dcf18 |
---|---|
1 | |
2 | |
3 | |
4 | |
5 import sys | |
6 import os | |
7 import re | |
8 import string | |
9 import commands | |
10 from tempfile import NamedTemporaryFile | |
11 | |
12 | |
13 # This function is exceedingly useful, perhaps package for reuse? | |
14 def getopts(argv): | |
15 opts = {} | |
16 while argv: | |
17 if argv[0][0] == '-': | |
18 opts[argv[0]] = argv[1] | |
19 argv = argv[2:] | |
20 else: | |
21 argv = argv[1:] | |
22 return opts | |
23 | |
24 | |
25 | |
26 def main(): | |
27 args = sys.argv[1:] | |
28 | |
29 try: | |
30 opts = getopts(args) | |
31 except IndexError: | |
32 print "Usage:" | |
33 print "-noColors colors" | |
34 print "-dictFile dictionary file" | |
35 print "-trieSink output file" | |
36 print "-targetLayerName " | |
37 print "-valueFeatures " | |
38 print "-keyIndex " | |
39 | |
40 verbose = opts.get("-verbose") | |
41 if verbose == None: | |
42 print "No value specified" | |
43 return -1 | |
44 | |
45 colors = opts.get("-noColors") | |
46 if colors == None: | |
47 print "No value specified" | |
48 return -2 | |
49 | |
50 dictFile = opts.get("-dictFile") | |
51 if dictFile == None: | |
52 print "No value specified" | |
53 return -3 | |
54 | |
55 trieSink = opts.get("-trieSink") | |
56 if trieSink == None: | |
57 print "No value specified" | |
58 return -4 | |
59 | |
60 targetLayerName = opts.get("-targetLayerName") | |
61 if targetLayerName == None: | |
62 print "No value specified" | |
63 return -5 | |
64 | |
65 valueFeatures = opts.get("-valueFeatures") | |
66 if valueFeatures == None: | |
67 print "No value specified" | |
68 return -6 | |
69 | |
70 keyIndex = opts.get("-keyIndex") | |
71 if keyIndex == None: | |
72 print "No value specified" | |
73 return -7 | |
74 | |
75 # generate alvisnlp commandOptions | |
76 commandOptions ="" | |
77 if verbose == "true" : | |
78 commandOptions = " -verbose " | |
79 | |
80 if colors == "true" : | |
81 commandOptions = commandOptions + "-noColors " | |
82 | |
83 commandline = "alvisnlp %s -param search dictFile %s -param search trieSink %s -param search targetLayerName %s -param search valueFeatures %s -param search keyIndex %s simpleprojector2.plan" % ( commandOptions , dictFile , trieSink , targetLayerName , valueFeatures , keyIndex ) | |
84 | |
85 # run alvisnlp | |
86 print commandline | |
87 | |
88 # errorcode, stdout = commands.getstatusoutput(commandline) | |
89 os.system(commandline) | |
90 | |
91 # return error code | |
92 #return errorcode | |
93 | |
94 | |
95 if __name__ == "__main__": | |
96 main() | |
97 |