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