comparison g_chart_parser.py @ 2:a47980ef2b96 draft

planemo upload for repository https://github.com/Alveo/alveo-galaxy-tools commit b5b26e9118f2ad8af109d606746b39a5588f0511-dirty
author stevecassidy
date Wed, 01 Nov 2017 01:19:55 -0400
parents fb617586f4b2
children
comparison
equal deleted inserted replaced
1:fb617586f4b2 2:a47980ef2b96
1 import sys 1 import sys
2 import nltk 2 import nltk
3 import argparse 3 import argparse
4 from nltk.corpus import PlaintextCorpusReader 4
5 5
6 def arguments(): 6 def arguments():
7 parser = argparse.ArgumentParser(description="run NER on a text") 7 parser = argparse.ArgumentParser(description="run NER on a text")
8 parser.add_argument('--input', required=True, action="store", type=str, help="input text file") 8 parser.add_argument('--input', required=True, action="store", type=str, help="input text file")
9 parser.add_argument('--grammar', required=True, action="store", type=str, help="grammar file") 9 parser.add_argument('--grammar', required=True, action="store", type=str, help="grammar file")
10 parser.add_argument('--output', required=True, action="store", type=str, help="output file path") 10 parser.add_argument('--output', required=True, action="store", type=str, help="output file path")
11 args = parser.parse_args() 11 return parser.parse_args()
12 return args
13 12
14 13
15 def chart_parse(in_file, grammar_file, out_file): 14 def chart_parse(in_file, grammar_file, out_file):
16 with open(in_file, 'r') as fd: 15 with open(in_file, 'r') as fd:
17 text = fd.read() 16 text = fd.read()
30 for t in trees: 29 for t in trees:
31 output.write(t.pformat()) 30 output.write(t.pformat())
32 output.write('\n') 31 output.write('\n')
33 32
34 except Exception as e: 33 except Exception as e:
35 message = "Error with parsing. Check the input files are correct and the grammar contains every word in the input sequence. \n----\n" + str(e) + "\n" 34 message = """Error with parsing. Check the input files are correct
35 and the grammar contains every word in the input sequence. \n----\n""" + str(e) + "\n"
36 sys.stderr.write(message) 36 sys.stderr.write(message)
37 sys.exit() 37 sys.exit()
38 output.close() 38 output.close()
39 39
40
40 if __name__ == '__main__': 41 if __name__ == '__main__':
41 args = arguments() 42 args = arguments()
42 chart_parse(args.input, args.grammar, args.output) 43 chart_parse(args.input, args.grammar, args.output)