LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong
Administrivia Last Time: http://perldoc.perl.org/perlintro.html Quick Quiz (you should have received an email back from me) Today's class: Quick Quiz Review Quick Homework 1 Continue with perlintro …
Quick Quiz on Chapter 1 Review NN = common noun NP = noun phrase VBD = verb past tense VP = verb phrase
Quick Quiz on Chapter 1 Review http://www.oed.com.ezproxy4.library.arizona.edu
Quick Quiz on Chapter 1 Review
Syntactic Labeling (Standard) How to read the parse http://languagelog.ldc.upenn.edu/myl/PennTreebank1995.pdf Phrasal Labels: VP = Verb Phrase, S = Sentence, SBAR = Embedded Sentences, NP = Noun Phrase, PP = Prepositional Phrase. ADJP = Adjectival Phrase. Basic declarative sentence: [S NP [VP VBD NP]] Part of Speech (POS) labels: DT = Determiner, JJ = Adjective, JJR = Adjective (Comparative Form), NN = Common Noun, NNS = Common Noun (plural), NNP = Proper Noun, VB = Verb (base form), VBD = Verb (past tense), IN = Preposition, PRP$ = Possessive Pronoun. More here: https://www.ling.upenn.edu/courses/Fall_2003/ling001/penn_treebank_pos.html
Quick Homework 1 Q1: What's supposed to be funny about this? Q2: Run the 1st sentence on the Berkeley Parser (from Quick Quiz 1). Critique the parse. Q3: Run the 1st sentence on the Google Parser. Critique the dependency parse. (https://cloud.google.com/natural-language/)
Quick Homework 1 email me your answers by the end of Wednesday Rules: Subject: 438/538 Your Name Homework 1 One PDF file only (include any diagrams) – no multiple attachments, no Word documents
Perl http://perldoc.perl.org/perlintro.html One-liner: perl -e 'PerlCode' Notes from the tutorial: whitespace not always necessary, e.g. print"Hello class!\n”; is fine, but good idea to consistently use spacing (not just for readability) variable names must not begin with a number (use a letter), so $538students is out $students538 is ok error messages are frequently uninformative (and sometimes misleading), e.g. Bareword found where operator expected at example.prl line 3, near "$538students" (Missing operator before students?) error not associated with the variable starting with a number “Nanny mode”: helps with debugging: makes you declare variables with my
print as a statement vs. function Perl Python3 Same behavior, different assumptions about end of line (\n) from these two programming languages escape character Note also the differences in syntax: (..) in Python3, no parentheses (needed) in Perl ; need to separate the statements in Perl, none in Python
Perl vs. Python3 Scalars: (basically things that take up one 32/64 bit word of memory) variables begin with ($) - no such type requirement in Python Numbers (integer, floating point) Python includes complex numbers (cmath library) Strings (double ".." or single quoted '..') References (pointers to (non-)scalars)
Perl vs. Python3 Variable interpolation Perl: Python3: Python2.7: print "My name is $name\n"; print "My name is \$name\n"; print 'My name is \$name\n'; Python3: print("My name is", name) Python2.7: Note: white spacing
Perl Arrays like a simple ordered list… (in Python, we use a list) Literal: @ARRAY = ( … , … , …) (round brackets; comma separator) Python: array = [… , … , … ] Access: $ARRAY[ INDEX] (zero-indexed; negative indices ok; slices ok) Python: array[index] Index of last element: $#array (a scalar) Python: array[-1] Coercion @ARRAY = number of elements in scalar context Python: len(array) Built-in functions: sort @ARRAY; reverse @ARRAY,; push @ARRAY, $ELEMENT; pop @ARRAY; shift @ARRAY; unshift @ARRAY, $ELEMENT, splice @ARRAY, $OFFSET, $LENGTH, $ELEMENT $ELEMENT above can be @ARRAY Python: array.sort(), array.reverse() Built-in arrays: @ARGV (command line arguments) @_ (sub(routine) arguments)
Exercises If you’re new to programming, practice using Perl read the intro and run all the examples!