annotate simpleprojector2.py @ 8:39c655c7ce96 draft default tip

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