LING 388: Language and Computers Sandiway Fong Lecture 9: 9/21.

Slides:



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

LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 13: 10/9.
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/27.
LING 388: Language and Computers Sandiway Fong 9/29 Lecture 11.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/24.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 16: 10/19.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 3: 8/29.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/21.
LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.
LING 388 Language and Computers Lecture 8 9/25/03 Sandiway FONG.
LING 364: Introduction to Formal Semantics Lecture 4 January 24th.
CSC 160 Computer Programming for Non-Majors Lecture #5: Defining Functions Prof. Adam M. Wittenstein
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/23.
LING 388 Language and Computers Lecture 3 9/09/03 Sandiway FONG.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/6.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/7.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/13.
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
LING 388: Language and Computers Sandiway Fong Lecture 11: 10/3.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/29.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/7.
LING 388 Language and Computers Take-Home Final Examination 12/9/03 Sandiway FONG.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/5.
LING 364: Introduction to Formal Semantics Lecture 3 January 19th.
LING 388: Language and Computers Sandiway Fong Lecture 10: 9/26.
LING 388 Language and Computers Lecture 7 9/23/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 16: 10/19.
LING 388: Language and Computers Sandiway Fong Lecture 4: 9/1.
CSC 160 Computer Programming for Non-Majors Lecture #3a: Stepper, Words, Sentences Prof. Adam M. Wittenstein
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
LING 388 Language and Computers Lecture 17 10/28/03 Sandiway FONG.
1 LING 438/538 Computational Linguistics Sandiway Fong Lecture 4: 8/31.
Regular Expressions Dr. Ralph D. Westfall May, 2011.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Overview of the grep Command Alex Dukhovny CS 265 Spring 2011.
CMPS 3223 Theory of Computation Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided.
LING 388: Language and Computers Sandiway Fong Lecture 4.
Computer Programming for Biologists Class 5 Nov 20 st, 2014 Karsten Hokamp
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 4: 8/30.
LING 388: Language and Computers Sandiway Fong Lecture 6.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
CIS 451: Regular Expressions Dr. Ralph D. Westfall January, 2009.
1 University of Palestine Topics In CIS ITBS 3202 Ms. Eman Alajrami 2 nd Semester
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
CSC 221 Computer Organization and Assembly Language
Introduction to Unix – CS 21 Lecture 6. Lecture Overview Homework questions More on wildcards Regular expressions Using grep Quiz #1.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/15.
Instructor: Craig Duckett Lecture 08: Thursday, October 22 nd, 2015 Patterns, Order of Evaluation, Concatenation, Substrings, Trim, Position 1 BIT275:
Regular Expressions This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this.
LING 388: Language and Computers Sandiway Fong 9/27 Lecture 10.
20-753: Fundamentals of Web Programming 1 Lecture 10: Server-Side Scripting II Fundamentals of Web Programming Lecture 10: Server-Side Scripting II.
May 2008CLINT-LIN Regular Expressions1 Introduction to Computational Linguistics Regular Expressions (Tutorial derived from NLTK)
Finding Things Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Operators Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
CSE 311: Foundations of Computing Fall 2013 Lecture 18: Structural induction, regular expressions.
-Joseph Beberman *Some slides are inspired by a PowerPoint presentation used by professor Seikyung Jung, which was derived from Charlie Wiseman.
OOP Tirgul 11. What We’ll Be Seeing Today  Regular Expressions Basics  Doing it in Java  Advanced Regular Expressions  Summary 2.
C++ Memory Management – Homework Exercises
Basic Scheme February 8, 2007 Compound expressions Rules of evaluation
LING/C SC/PSYC 438/538 Lecture 10 Sandiway Fong.
Sequences Objectives:
LING 408/508: Computational Techniques for Linguists
Programming Techniques
CSE 303 Concepts and Tools for Software Development
Sequences Objectives:
Presentation transcript:

LING 388: Language and Computers Sandiway Fong Lecture 9: 9/21

2 Administrivia Homework 2 Review Homework 3 –out today –you’ll need file WSJ9_040.txt from the course homepage –due next Thursday

3 Homework Question 1 (6pts) Give the complete (i.e. all answers) step-by-step computation tree for ?- mem([1,2,3],X). given the database –mem([X|_],X). –mem([_|L],X):- mem(L,X). Hint: using –?- trace. –will help but you will need to list out the matches and variable binding at each step –see Lecture 5 slides for app/3 to see what format you should use

4 Homework Question 1 (6pts) Give the complete (i.e. all answers) step-by-step computation tree for ?- mem([1,2,3],X). given the database –mem([X|_],X). –mem([_|L],X):- mem(L,X). ?- mem([1,2,3],X). match base case mem([X’|_],X’). when X’=1 and X=X’ Answer : X=1 match recursive case mem([_|L],X’) when [2,3]=L and X=X’ ?- mem([2,3],X’). match base case mem([X”|_],X”). when X”=2 and X’=X” Answer : X=2

5 Homework Question 1 mem([X|_],X). mem([_|L],X):- mem(L,X). ?- mem([1,2,3],X). match base case mem([X’|_],X’). when X’=1 and X=X’ Answer : X=1 match recursive case mem([_|L],X’) when [2,3]=L and X=X’ ?- mem([2,3],X’). match base case mem([X”|_],X”). when X”=2 and X’=X” Answer : X=2 ?- mem([2,3],X’). match recursive case mem([_|L’],X”) when [3]=L’ and X’=X” ?- mem([3],X”). match base case mem([X”’|_],X”’). when X”’=3 and X”=X”’ Answer : X=3 ?- mem([3],X”). match recursive case mem([_|L”],X”’) when []=L” and X”=X”’ ?- mem([],X”’). No match

6 Homework Question 2 Database addNT(W,Wnt) :- atom_chars(W,L), append(L,[n,’\’’,t],Lnt), atom_chars(Wnt,Lnt). modal(should). “should is a modal” modal(would). “would is a modal” modal(could). “could is a modal” modal(may). “may is a modal” (4pts) Modify the definition of addNT/2 to accept only modals Demonstrate your program works correctly for: ?- addNT(should,X). ?- addNT(would,X). ?- addNT(john,X). Submit both your program and queries as your answer –put everything together, –not in separate files!

7 Homework Question 2 Database addNT(W,Wnt) :- atom_chars(W,L), append(L,[n,’\’’,t],Lnt), atom_chars(Wnt,Lnt). modal(should). “should is a modal” modal(would). “would is a modal” modal(could). “could is a modal” modal(may). “may is a modal” Idea: –make addNT/2 be true only if word W is a modal –i.e. call modal(W) as a sub- query of addNT/2 Revised definition of addNT/2 addNT(W,Wnt) :- modal(W), atom_chars(W,L), append(L,[n,’\’’,t],Lnt), atom_chars(Wnt,Lnt).

8 Homework Question 2 (4pts) Further modify your definition of addNT/2 to exclude the ungrammatical case: –shouldshouldn’t –wouldwouldn’t –couldcouldn’t –may*mayn’t –i.e. ?- addNT(may,X). No Idea: –make sure W cannot be may –i.e. call \+ W = may as a sub-query of addNT/2 Revised definition of addNT/2 addNT(W,Wnt) :- \+ W = may, modal(W), atom_chars(W,L), append(L,[n,’\’’,t],Lnt), atom_chars(Wnt,Lnt).

9 Homework Question 2 (6pts) Extra Credit Question Notice that the following query doesn’t work: ?- addNT(X,'shouldn\'t'). ERROR: atom_chars/2: Arguments are not sufficiently instantiated Write the corresponding “subtract n’t” rule, call it subNT/2, for removing the n’t suffix: ?- addNT(X,'shouldn\'t'). X = should

10 Homework Question 2 Original definition addNT(W,Wnt) :- atom_chars(W,L), append(L,[n,’\’’,t],Lnt), atom_chars(Wnt,Lnt). Query ?- addNT(should,X). instantiates W = should Definition becomes addNT( should,Wnt) :- atom_chars(should,L), append(L,[n,’\’’,t],Lnt), atom_chars(Wnt,Lnt). Query ?- ?- addNT(X,'shouldn\'t'). instantiates Wnt = 'shouldn\'t' Definition becomes addNT(W,’ shouldn\’t’ ) :- atom_chars(W,L), append(L,[n,’\’’,t],Lnt), atom_chars(Wnt,Lnt). Problem! atom_chars cannot operate without either an atom or list supplied

11 Homework Question 2 Original definition addNT(W,Wnt) :- atom_chars(W,L), append(L,[n,’\’’,t],Lnt), atom_chars(Wnt,Lnt). Reverse the order of the sub-goals in the original definition subNT(W,Wnt) :- atom_chars(Wnt,Lnt), append(L,[n,’\’’,t],Lnt), atom_chars(W,L).

12 Homework Question 3 (6pts) Define a predicate pallindrome/1 –that is true when a word can be spelt the same forwards or backwards Examples: –radar –redivider –abba Definition reverse([],[]). reverse([X|L],R) :- reverse(L,LR), append(LR,[X],R).

13 Homework Question 3 (6pts) Define a predicate pallindrome/1 –that is true when a word can be spelt the same forwards or backwards Definition reverse([],[]). reverse([X|L],R) :- reverse(L,LR), append(LR,[X],R). Examples: –radar –redivider –abba Idea: –[r,a,d,a,r] reversed is [r,a,d,a,r] i.e. the same list! pallindrome(W) :- atom_chars(W,L), reverse(L,L).

14 Homework 3

15 Data File please use a computer with Microsoft Word for this homework –machines in SBS RI Computer Lab 224 (or any other lab) can be used in Microsoft Word –load file WSJ9_040.txt from the course homepage Wall Street Journal articles (July 28th– August 1st 1989) this is the text file you will use for searching contains almost 14,500 lines

16 Last Time introduced the notion of a regular expression –pattern matching –important in document searching varieties –grep “global regular expression print” –Microsoft Word’s Find with wildcard somewhat limited form of regular expression search

17 Microsoft Word’s Find basic wildcards –? and * ? any single character *zero or more characters one or more of the preceding character – < beginning of a word > end of a word –[ ] range of characters e.g. [aeiou], [a-z], [A-z], [0-9] –more wildcards can be found in the help documentation

18 Ordinals n-th –expression “one or more occurrences of a character in the range 0 to 9, followed by th and the word boundary” –finds In 4th quarter 17th-largest 17th-largest(part of above string) its 100,000th case(matches 3 times)

19 Ordinals 1st –expression 1st> –finds 21st anniversary concert 1st American 2nd –expression 2nd> –finds 2nd-Period 3rd –expression 3rd> combining expressions –[23][nr]d> “2 or 3, followed by n or r, followed by d, and a word boundary” works since 2rd and 3nd won’t be present –[123][snr][td]> 1st, 2nd, and 3rd “one or more occurrences of a character in the range 0 to 9, followed by one of t,s, n, or r, followed by one of h, t, or d and the word boundary” 1st, 2nd, 3rd, and 4th and so on...

20 Exercise 1 Since this is the Wall Street Journal Try to find occurrences of $X millions Regular Expression millions –You need to use Find –Turn on Wildcard searching

21 Homework Exercise 1 Numbers (3pts) –Question 1 (2pts) Give a single Microsoft Word regular expression for finding occurrences of –$number million where number not is a whole number of millions, e.g. –$25.3 million –$826.7 million –$3.1 million –Question 2 (1pts) How many are there of this kind in the document?

22 Homework Exercise 2 Words (5pts) –Question 1 (2pts) Give a single Microsoft Word regular expression for finding occurrences of the following terms –spokesman –spokesmen –spokeswoman –spokeswomen –Question 2 (1pt) How many are there in the document? –Question 3 (1pt) What does your expression assume about words in English? –Question 4 (1pt) Why is the answer different from a simple spokes* search?

23 Homework Exercise 3 Document Structure (8pts) Many articles contains a header line naming its author(s), e.g. By Carrie Dolan By Ron Winslow and Michael Waldholz By Jeffrey H. Birnbaum and By are separated by exactly 2 spaces –Question 1 (2pts) Give a Microsoft Word regular expression to find header lines with first authors who use a middle initial –Question 2 (1pt) How many such articles are there in the document?

24 Homework Exercise 3 Document Structure –Limitations of Microsoft Word Task: find articles authored by two people, By Ron Winslow and Michael Waldholz Expression: By* careful with that *! not the results we want!

25 Homework Exercise 3 Document Structure –Question 3 (4pts) Devise multiple regular expressions to find two author header By Ron Winslow and Michael By S. Karene Witcher and Jeffrey A. Trachtenberg HINT: –to overcome Microsoft Word’s behavior you will have to break up the search into multiple cases –Question 4 (1pt) How many such header lines are there in the document?

26 Summary Total: 16 pts –Exercise 1: Numbers (3pts) –Exercise 2: Words (5pts) –Exercise 3: Document structure (8pts)