80 likes | 226 Views
LING/C SC/PSYC 438/538. Lecture 4 9/1 Sandiway Fong. Administrivia. Reminder homework from lecture 3 due: next Tuesday midnight (I want to go through it in class next Wednesday) Guest lectures Dr. Nirav Merchant, Bioinformatics, Monday September 20 th
E N D
LING/C SC/PSYC 438/538 Lecture 4 9/1 Sandiway Fong
Administrivia • Reminder • homework from lecture 3 • due: next Tuesday midnight • (I want to go through it in class next Wednesday) • Guest lectures • Dr. Nirav Merchant, Bioinformatics, Monday September 20th • Dr. Ray Tillman,US Air Force Research Labs, Mesa AZ, TBA
Adminstrivia • Related course • LING 408 / 508, Fall 2010 • Computational Techniques for Linguists • Instructor: Erwin Chan • Monday, Wednesday, Friday 12:00-12:50 PM, Social Sciences 224 • This course will introduce students to computer programming for analyzing linguistic data. The programming languages to be used are Python and R. • http://www.u.arizona.edu/~echan3/508/508-fa10-syllabus.pdf
Sentiment Analysis • (thanks: Don Merson) • http://www.kurzweilai.net/mining-mood-swings-on-the-real-time-web • Viralheat uses natural-language processing and machine learning to sift through Twitter, Facebook fan pages, viral video sites, and Google Buzz posts to determine the Web’s collective sentiment toward various topics. go beyond how often something is mentioned
Perl Week • Last topics today • Other useful things for arrays: shift, unshift, push, pop • simple file input/output (I/O) • $ARGV[0] • Reading • http://perldoc.perl.org/perlintro.html • Section on Regular expressions • in conjunction with chapter 2 of JM
Perl Week Generalized form • Arrays: • insertion and deletion from the ends 0 1 2 n-2 n-1 shift/unshift pop/push
Perl Week Files: must be opened for reading or writing (overwrite or append modes) Opening a file creates a file handle (Perl variable) – not to be confused with filename Specify the file handle from input or writing to output
Perl Week • Example Perl code (template) for reading in a file line-by-line (file 4.prl): open($txtfile, $ARGV[0]) or die "$ARGV[0] not found!\n"; while ($line = <$txtfile>) { print "$line"; } • the command $line = <$txtfile> reads in from the file referenced by the file handle $txtfilea single line at a time (including the newline at the end of the line) and places that line in the variable $line. (At the end of the file, $line is just an empty string – which fails the while condition and thus exits the loop.) • the filename is picked up from the command line and placed in the array @ARGV. • Hence: • perl 4.prl words2.txt • returns words2.txt not found! via the die statement because the open statement would evaluate to false (assuming words2.txt doesn’t exist). The while loop doesn’t get executed at all. • But • perl 4.prl words.txt • would execute the while loop and print each line of the file when words.txtexists.