tagger - #!/usr/bin/python

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #!/usr/bin/python ############################################################ # Main Program ############################################################ if __name__ == '__main__': import sys import string try: import psyco psyco.full() except: print >> sys.stderr, 'Warning: No psyco available' # COMMANDLINE: tagger.py training_file test_file if len(sys.argv) > 2: training_file = sys.argv[1] test_file = sys.argv[2] elif len(sys.argv) > 1: training_file = sys.argv[1] print >> sys.stderr, 'No test file!\n' else: print >> sys.stderr, 'Usage: tagger.py <training_file> <test_file>' # sys.stderr is the file like object that corresponds to STDERR # Reading training data best_tag={} ## best tag for word: = most frequent tag default_tag='' ## tag with best overall count try: fsock_train=open(training_file,'r',0) print >> sys.stderr, 'Reading %s' % training_file word_tag_matrix={} ## word tag pair counts ## For word tag pairs, each key-value pair: a pair of a word and a tag ## ## word_tag_matrix.get(('all','DET0'),0) = the number of 'all' tokens ## word_tag_matrix....
View Full Document

Page1 / 2

tagger - #!/usr/bin/python

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online