LING/C SC/PSYC 438/538 Lecture 5 9/8 Sandiway Fong.

Slides:



Advertisements
Similar presentations
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.
Advertisements

LING/C SC/PSYC 438/538 Lecture 12 Sandiway Fong. Administrivia We'll postpone Homework 4 review until next week …
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong. Administrivia Homework 1 graded – you should have gotten an from me.
LING/C SC/PSYC 438/538 Lecture 4 9/1 Sandiway Fong.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 3: 8/28.
CS 898N – Advanced World Wide Web Technologies Lecture 8: PERL Chin-Chih Chang
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/11.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/28.
Designing Algorithms Csci 107 Lecture 4.
COS 381 Day 22. Agenda Questions?? Resources Source Code Available for examples in Text Book in Blackboard
Lecture 2 BNFO 135 Usman Roshan. Perl variables Scalar –Number –String Examples –$myname = “Roshan”; –$year = 2006;
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong. Adminstrivia.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 8: Perl Basics Fundamentals of Web Programming.
LING/C SC/PSYC 438/538 Lecture 2 Sandiway Fong. Today’s Topics Did you read Chapter 1 of JM? – Short Homework 1 (submit by midnight Saturday) Some slides.
LING/C SC/PSYC 438/538 Lecture 5 Sandiway Fong. Today’s Topics File input/output – open, References Perl modules Homework 2: due next Monday by midnight.
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
MCB 5472 Assignment #6: HMMER and using perl to perform repetitive tasks February 26, 2014.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 4: 8/30.
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong. Continuing with Perl Homework 3: first Perl homework – due Sunday by midnight – one PDF file, by .
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
LING/C SC/PSYC 438/538 Lecture 2 Sandiway Fong. Today’s Topics Did you read Chapter 1 of JM? – Short Homework 2 (submit by midnight Friday) Today is Perl.
LING/C SC/PSYC 438/538 Lecture 7 9/15 Sandiway Fong.
Meet Perl, Part 2 Flow of Control and I/O. Perl Statements Lots of different ways to write similar statements –Can make your code look more like natural.
LING/C SC/PSYC 438/538 Lecture 3 8/30 Sandiway Fong.
Perl Practical(?)‏ Extraction and Report Language.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
CS 330 Programming Languages 10 / 07 / 2008 Instructor: Michael Eckmann.
Perl Language Yize Chen CS354. History Perl was designed by Larry Wall in 1987 as a text processing language Perl has revised several times and becomes.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong. Administrivia Homework 2 graded.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
read and learn from example loop programs develop modular program
LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong. Administrivia Reading Homework – Chapter 3 of JM: Words and Transducers.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Strings and Patterns in Perl Ellen Walker Bioinformatics Hiram College.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Topic 4:Subroutines CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 4, pages 56-72, Programming Perl 3rd edition pages 80-83,
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong. Adminstrivia Homework 4 not yet graded …
Digital Text and Data Processing Tokenisation. Today’s class □ Tokenisation and creation of frequency lists □ Keyword in context lists □ Moretti and distant.
LING/C SC/PSYC 438/538 Lecture 14 Sandiway Fong. Administrivia Homework 6 graded.
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
Creating Databases for Web Applications 3-Tier. Design vs Function vs Content. More SQL. More php. Homework: work on final projects.
Week Four Agenda Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems Upcoming deadlines.
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong. Homework 4 Submit one PDF file Your submission should include code and sample runs Due date Monday 21.
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
LING/C SC/PSYC 438/538 Online Lecture 7 Sandiway Fong.
Perl Chapter 3 Conditional statements. Control Expressions Control expressions – interpreted as T/F (evaluated as strings or numbers) – simple, relational,
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Perl References arrays and hashes can only contain scalars (numbers and strings)‏ if we want something more complicated (like an array of arrays) we use.
Introduction to Programming the WWW I CMSC Winter 2004 Lecture 8.
Chapter 5 - Control Structures: Part 2
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 7 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 6 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 10 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 12 Sandiway Fong.
LING 408/508: Computational Techniques for Linguists
LING/C SC/PSYC 438/538 Lecture 18 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 7 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 3 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 12 Sandiway Fong.
Presentation transcript:

LING/C SC/PSYC 438/538 Lecture 5 9/8 Sandiway Fong

Administrivia Homework 1 (from lecture 3) – was due last night (at midnight)

Today’s Topics Review – Homework 1 – We’ll go through it in class today Chapter 2 of JM – Section 2.1 on regular expressions – (which you’ve already read…)

Safari Book available online (Thanks! Don Merson) UA Library has been given access to the full Safari Books Online service. This allows you to read a vast number of technical books via your browser. However, it is currently only a trial.

Homework Review Question 1: 438 and 538 (7 points) – Given = (I, saw, the, the, cat, on, the, mat); = (the, cat, sat, on, the, mat); – Write a simple Perl program which detects repeated words (many spell checker/grammar programs have this capability) – It should print a message stating the repeated word and its position if one exists – e.g. word 3 “the” is repeated in the case of sentence1 – No repeated words found in the case of sentence2 – note: output multiple messages if there are multiple repeated words – Hint: use a loop – Submit your Perl code and show examples of your program working

Homework Review Thinking algorithmically… w1w1 w2w2 w3w3 w4w4 w5w5 Compare w 1 with w 2 Compare w 2 with w 3 Compare w 3 with w 4 Compare w 4 with w 5

Array indices start from 0… Homework Review Turning an algorithm into Perl code: Compare w 1 with w 1+1 Compare w 2 with w 2+1 Compare w n-2 with w n-2+1 Compare w n-1 with w n “for” loop implementation words 0,words 1 … words n-1 for ($i=0; $i<$#words; $i++) { compare word indexed by $i to word indexed by $i+1 if same string, print message } Array indices end at $#words…

Homework Review First iteration (there are many ways to do this…) – (the basic for-loop) = (I, saw, the, the, cat, on, the, mat); = (the, cat, sat, on, the, mat); for ($i=0; $i<$#words; $i++) { if ($words[$i] eq $words[$i+1]) { print "word $i \"$words[$i]\" is repeated\n" }

Homework Review 2 nd iteration – (setting a flag when a repeated word is found) – (condition the output based on the value of the flag) my $flag = 0; for ($i=0; $i<$#words; $i++) { if ($words[$i] eq $words[$i+1]) { print "word $i \"$words[$i]\" is repeated\n"; $flag = 1 } print "No words repeated\n" unless $flag

Homework Review 3 rd iteration – (encapsulating the loop in a subroutine) sub check_repeated { my $flag = 0; for ($i=0; $i<$#words; $i++) { if ($words[$i] eq $words[$i+1]) { print "word $i \"$words[$i]\" is repeated\n"; $flag = 1 } print "No words repeated\n" unless $flag } print print print print

Homework Review Question 2: 438 and 538 (3 points) – Describe what would it take to stop a repeated word program from flagging legitimate examples of repeated words in a sentence – (No spell checker/grammar program that I know has this capability) – Examples of legitimately repeated words: I wish that that question had an answer Because he had had too many beers already, he skipped the Friday office happy hour

Homework Review Question 3: 538 (10 points), (438 extra credit) – Write a simple Perl program that outputs word frequencies for a sentence – E.g. given = (I, saw, the, cat, on, the, mat, by, the, saw, table); – output a summary that looks something like: – the occurs 4 times – saw occurs twice – I, car, mat, on, by, table occurs once only – Hint: build a hash keyed by word with value frequency – Submit your Perl code and show examples of your program working

Homework Review Thinking algorithmically… w1w1 w2w2 w3w3 w4w4 w5w5 w0w0 foreach $word w0w0 hash data structure = “labeled medicine cabinet”

Homework Review Sample = (the, cat, sat, on, the, mat, that, the, cat, likes, most); %freq = (); foreach $word { if (exists $freq{$word}) { $freq{$word}++; } else { $freq{$word} = 1; } foreach $word (keys %freq) { print "$word occurs $freq{$word} time(s)\n"; } perl e2.prl on occurs 1 time(s) the occurs 3 time(s) cat occurs 2 time(s) most occurs 1 time(s) sat occurs 1 time(s) likes occurs 1 time(s) that occurs 1 time(s) mat occurs 1 time(s) perl e2.prl on occurs 1 time(s) the occurs 3 time(s) cat occurs 2 time(s) most occurs 1 time(s) sat occurs 1 time(s) likes occurs 1 time(s) that occurs 1 time(s) mat occurs 1 time(s) Further simplifications to the code are possible but the basic logic remains

Chapter 2: JM Today – using your Perl skills on – Section 2.1 Regular Expressions – Online tutorials

Pattern Matching JM, Chapter 2, pg 17 Merriam-Webster online

Chapter 2: JM Perl regular expression (re) matching: – $a =~ /foo/ – /…/ contains a regular expression – will evaluate to true/false depending on what’s contained in $a Perl regular expression (re) match and substitute: – $a =~ s/foo/bar/ – s/…match… /…substitute… / contains two expressions – will modify $a by looking for a single occurrence of match and replacing that with substitute – s/…match… /…substitute… /g global match and substitute

Chapter 2: JM Most useful with code for reading in a file line-by-line: open($txtfile,$ARGV[0]) or die "$ARGV[0] not found!\n"; while ($line = ) { do RE stuff with $line }

Chapter 2: JM

Sheeptalk

Chapter 2: JM

Precedence of operators – Example: Column 1 Column 2 Column 3 … – /Column [0-9]+ */ – /(Column [0-9]+ *)*/ – /house(cat(s|)|)/ Perl: – In a regular expression the pattern matched by within the pair of parentheses is stored in $1 (and $2 and so on) Precedence Hierarchy:

Chapter 2: JM A shortcut: list context for matching

Chapter 2: JM s/([0-9]+)/ /