annotate alvis-annotator.py @ 3:047f65d57d81 draft

Uploaded
author moba
date Tue, 02 May 2017 06:04:50 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
047f65d57d81 Uploaded
moba
parents:
diff changeset
1 #!/usr/bin/python2
047f65d57d81 Uploaded
moba
parents:
diff changeset
2
047f65d57d81 Uploaded
moba
parents:
diff changeset
3 # Filename: grep.py
047f65d57d81 Uploaded
moba
parents:
diff changeset
4 # Author: Mouhamadou Ba
047f65d57d81 Uploaded
moba
parents:
diff changeset
5 # Version: 20/07/2016
047f65d57d81 Uploaded
moba
parents:
diff changeset
6
047f65d57d81 Uploaded
moba
parents:
diff changeset
7 # This function is exceedingly useful, perhaps package for reuse?
047f65d57d81 Uploaded
moba
parents:
diff changeset
8 def getopts(argv):
047f65d57d81 Uploaded
moba
parents:
diff changeset
9 opts = {}
047f65d57d81 Uploaded
moba
parents:
diff changeset
10 while argv:
047f65d57d81 Uploaded
moba
parents:
diff changeset
11 if argv[0][0] == '-':
047f65d57d81 Uploaded
moba
parents:
diff changeset
12 opts[argv[0]] = argv[1]
047f65d57d81 Uploaded
moba
parents:
diff changeset
13 argv = argv[2:]
047f65d57d81 Uploaded
moba
parents:
diff changeset
14 else:
047f65d57d81 Uploaded
moba
parents:
diff changeset
15 argv = argv[1:]
047f65d57d81 Uploaded
moba
parents:
diff changeset
16 return opts
047f65d57d81 Uploaded
moba
parents:
diff changeset
17
047f65d57d81 Uploaded
moba
parents:
diff changeset
18
047f65d57d81 Uploaded
moba
parents:
diff changeset
19
047f65d57d81 Uploaded
moba
parents:
diff changeset
20 def main():
047f65d57d81 Uploaded
moba
parents:
diff changeset
21 args = sys.argv[1:]
047f65d57d81 Uploaded
moba
parents:
diff changeset
22
047f65d57d81 Uploaded
moba
parents:
diff changeset
23 try:
047f65d57d81 Uploaded
moba
parents:
diff changeset
24 opts = getopts(args)
047f65d57d81 Uploaded
moba
parents:
diff changeset
25 except IndexError:
047f65d57d81 Uploaded
moba
parents:
diff changeset
26 print "Usage:"
047f65d57d81 Uploaded
moba
parents:
diff changeset
27 print "-input text corpus"
047f65d57d81 Uploaded
moba
parents:
diff changeset
28 print "-dict dictionary file"
047f65d57d81 Uploaded
moba
parents:
diff changeset
29 print "-output output file"
047f65d57d81 Uploaded
moba
parents:
diff changeset
30
047f65d57d81 Uploaded
moba
parents:
diff changeset
31
047f65d57d81 Uploaded
moba
parents:
diff changeset
32 input_p = opts.get("-input")
047f65d57d81 Uploaded
moba
parents:
diff changeset
33 if input_p == None:
047f65d57d81 Uploaded
moba
parents:
diff changeset
34 print "No value specified"
047f65d57d81 Uploaded
moba
parents:
diff changeset
35 return -1
047f65d57d81 Uploaded
moba
parents:
diff changeset
36
047f65d57d81 Uploaded
moba
parents:
diff changeset
37 dict_p = opts.get("-dict")
047f65d57d81 Uploaded
moba
parents:
diff changeset
38 if dict_p == None:
047f65d57d81 Uploaded
moba
parents:
diff changeset
39 print "No value specified"
047f65d57d81 Uploaded
moba
parents:
diff changeset
40 return -2
047f65d57d81 Uploaded
moba
parents:
diff changeset
41
047f65d57d81 Uploaded
moba
parents:
diff changeset
42 output_p = opts.get("-output")
047f65d57d81 Uploaded
moba
parents:
diff changeset
43 if output_p == None:
047f65d57d81 Uploaded
moba
parents:
diff changeset
44 print "No value specified"
047f65d57d81 Uploaded
moba
parents:
diff changeset
45 return -3
047f65d57d81 Uploaded
moba
parents:
diff changeset
46
047f65d57d81 Uploaded
moba
parents:
diff changeset
47 # generate alvisnlp commandOptions
047f65d57d81 Uploaded
moba
parents:
diff changeset
48 commandOptions =""
047f65d57d81 Uploaded
moba
parents:
diff changeset
49 if verbose == "true" :
047f65d57d81 Uploaded
moba
parents:
diff changeset
50 commandOptions = " -verbose "
047f65d57d81 Uploaded
moba
parents:
diff changeset
51
047f65d57d81 Uploaded
moba
parents:
diff changeset
52 if colors == "true" :
047f65d57d81 Uploaded
moba
parents:
diff changeset
53 commandOptions = commandOptions + "-noColors "
047f65d57d81 Uploaded
moba
parents:
diff changeset
54
047f65d57d81 Uploaded
moba
parents:
diff changeset
55 commandline = "alvisnlp -param input %s -param dict %s -param output %s plans/alvis-annotator.plan" % ( input_p , dict_p , output_p )
047f65d57d81 Uploaded
moba
parents:
diff changeset
56
047f65d57d81 Uploaded
moba
parents:
diff changeset
57 # run alvisnlp
047f65d57d81 Uploaded
moba
parents:
diff changeset
58 print commandline
047f65d57d81 Uploaded
moba
parents:
diff changeset
59
047f65d57d81 Uploaded
moba
parents:
diff changeset
60 # errorcode, stdout = commands.getstatusoutput(commandline)
047f65d57d81 Uploaded
moba
parents:
diff changeset
61 os.system(commandline)
047f65d57d81 Uploaded
moba
parents:
diff changeset
62
047f65d57d81 Uploaded
moba
parents:
diff changeset
63 # return error code
047f65d57d81 Uploaded
moba
parents:
diff changeset
64 #return errorcode
047f65d57d81 Uploaded
moba
parents:
diff changeset
65
047f65d57d81 Uploaded
moba
parents:
diff changeset
66
047f65d57d81 Uploaded
moba
parents:
diff changeset
67 if __name__ == "__main__":
047f65d57d81 Uploaded
moba
parents:
diff changeset
68 main()
047f65d57d81 Uploaded
moba
parents:
diff changeset
69