LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong
Administrivia Today's Topics Quick Homework 4 graded (you should have an email from me) Today's Topics Terminal log from last time A note on Windows 10 and quoting Review of Homework 4 Continuing on with perlintro (scalars and arrays)
Terminal: from last time ~$ perl test.perl Can't open perl script "test.perl": No such file or directory ~$ pwd /Users/sandiway ~$ cd Desktop Desktop$ pwd /Users/sandiway/Desktop Desktop$ perl test.perl Hello, worldDesktop$ perl test.perl Hello, world Hello, world\nDesktop$ perl test.perl Desktop$ perl test.perl Hello, world Desktop$ perl -e 'print "Hello, World"' Hello, WorldDesktop$ perl -e 'print "Hello, World\n"' Hello, World Desktop$ perl -le 'print "Hello, World"' Name "main::Hello" used only once: possible typo at test.perl line 3. print() on unopened filehandle Hello at test.perl line 3.
Terminal: from last time Desktop$ perl test.perl Global symbol "$Hello" requires explicit package name (did you forget to declare "my $Hello"?) at test.perl line 3. Global symbol "$Hello" requires explicit package name (did you forget to declare "my $Hello"?) at test.perl line 4. Execution of test.perl aborted due to compilation errors. This is a stringDesktop$ perl test.perl This is a string\nDesktop$ perl test.perl This is a string Desktop$ perl test.perl Name "main::Hello" used only once: possible typo at test.perl line 3. Name "main::Helo" used only once: possible typo at test.perl line 4. Use of uninitialized value $Helo in string at test.perl line 4.
Terminal: from last time Desktop$ perl test.perl Global symbol "$Hello" requires explicit package name (did you forget to declare "my $Hello"?) at test.perl line 3. Global symbol "$Helo" requires explicit package name (did you forget to declare "my $Helo"?) at test.perl line 4. Execution of test.perl aborted due to compilation errors. Desktop$ MacOS: aquamacs editor TextEdit Linux: nano emacs Windows 10: Notepad
Terminal: from last time Windows 10 command prompt single quotes not recognized as quotes double quotes can be used inside the (initial) double quotes, everything will be passed to Perl: you can use single quotes you can escape double quotes, i.e. \" to get a double quote.
Terminal: from last time You can also use PowerShell in Windows 10: both single and double quotes can be used as quoting characters in the shell. Inside the initial quotes, you can escape any quotes that need to be passed to Perl.
Terminal: from last time ~$ cd Desktop Desktop$ python3 Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print("Hello, World") Hello, World >>> print "Hello, world\n"; File "<stdin>", line 1 print "Hello, world\n"; >>> SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello, world\n")? >>> print "Hello, world\n"; File "<stdin>", line 1 print "Hello, world\n"; ^ >>> >>> print("Hello, World") Hello, World >>> print('Hello, World') >>> print('Hello, World\n') >>> print('Hello, World\n\n\n\n\n')
Homework 4 Review 1. Commas are important people. Q2: Run the these two sentences on the Berkeley Parser. Critique the parse. (http://tomato.banatao.berkeley.edu:8080/parser/parser.html) Q3: Compare with the Google Parser. Critique the dependency parses. (https://cloud.google.com/natural-language/)
Homework 4 Review Berkeley Parser
Homework 4 Review Google Parser ATTR - link between a verb like 'be/seem/appear' and its complement https://nlp.stanford.edu/software/dependencies_manual.pdf attr has been removed as a relation. attr was a relation intended for the complement of a copular verb such as “to be”, “to seem”, “to appear”. Mainly, it was used for WHNP complements. (The relation attr was meant to stand for “attributive” but that was arguably a misuse of the word.)
Homework 4 Review Periods are important, people! Compare!
Homework 4 Review Capitalization is important, people! Compare!
print as a statement vs. function Perl Python3 Same behavior, different assumptions about end of line (\n) from these two programming languages "\" is the 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
perlintro: 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: len(array)-1 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)
perlintro Notes from the tutorial: semicolon (;) is not always necessary Command separator semantics vs. end of command (termination) token Best practice? Terminate every command with a semicolon Variable types: Every variable type has its own namespace. This means that $foo and @foo are two different variables. It also means that $foo[1] is a part of @foo, not a part of $foo. This may seem a bit weird, but that's okay, because it is weird.
Perl Arrays Arrays: A note on output: Idea: list of scalars like a simple ordered list (cf. Python lists) access by index: 0,1,2,… negative indices count from the end -2..-1 A note on output: print @a zeroonetwothreefour print "@a" zero one two three four controlled by system variable $" default value: a space
perlintro: 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: len(array)-1 (access: array[-1])
Shell quoting Bash shell (MacOS, Linux): cf. Windows 10 slide earlier manual: http://www.gnu.org/software/bash/manual/ can't write: perl -e '@a=(\'a\',\'b\',\'c\'); print "@a\n"'
Shell quoting Bash shell (MacOS, Linux): can write: perl -e "@a=(\"a\",\"b\",\"c\"); print \"@a\n\""
perlintro: Perl Arrays like a simple ordered list… (in Python, we use a list) Coercion @ARRAY = number of elements in scalar context Python (no coercion): 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(), NO push (use array.append() instead), array.pop(), No shift/unshift etc… Built-in arrays: @ARGV (command line arguments) @_ (sub(routine) arguments)
perlintro: Perl Arrays Similar to pop/push, but operates at the left end of the array Python doesn't have these defined but can be simulated via slicing and concatenation: array[1:] list + array
perlintro: Perl Arrays