{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

tagger - /usr/bin/python Main Program if_name =_main import...

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

View Full Document Right Arrow Icon
#!/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 tagged as DET0 ## 0 is what to return if (key,val) does not occurr in matrix... ## safe when ('all','DET0') has never been seen ## incrementing (safe for 1st occurrence of key,val) ## word_tag_matrix['all','DET0'] = word_tag_matrix.get(('all','DET0'),0) +1
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern