Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG.

Similar presentations


Presentation on theme: "LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG."— Presentation transcript:

1 LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG

2 Administrivia Computer Laboratory next time as well … Computer Laboratory next time as well …  November 4th in SBS 224 Homework 4 Homework 4  3 exercises today  1 extra-credit question  Homework 4 continues next time Lecture 17 slides updated… Lecture 17 slides updated…  Added an appendix illustrating the use of negation to implement counting up to 2 instead of the extra argument method [from suggestion in class]

3 Exercise 1: Relative Clauses Examples: Examples:  The cat that John saw(object)  The cat that saw John(subject)

4 Exercise 1: Relative Clauses Sample DCG: Sample DCG:  s(s(X,Y)) --> np(X), vp(Y).  vp(vp(X,Y)) --> transitive_verb(X), np(Y).  np(np(X)) --> proper_noun (X). % Special rules for relative clauses  np(np(np(Y,Z),U)) --> det(Y), common_noun(Z), sbar(U).  np(np(x)) --> [].  sbar(lambda(x,Y)) --> complementizer, s(Y).  complementizer --> [that]. % Lexicon  transitive_verb(v(hit)) --> [hit]. transitive_verb(v(saw)) --> [saw].  proper_noun(john) --> [john]. proper_noun(mary) --> [mary].  common_noun(n(man)) --> [man]. common_noun(n(cat)) --> [cat].  det(det(the)) --> [the].

5 Exercise 1: Relative Clauses Consult DCG Consult DCG Parsing noun phrases (NPs): Parsing noun phrases (NPs):  Run queries  ?- np(X,[the,cat,that,john,saw],[]).  ?- np(X,[the,cat,that,saw,john],[]). Verify DCG also (incorrectly) accepts as NPs: Verify DCG also (incorrectly) accepts as NPs:  *The cat that John saw Mary  *The cat that saw

6 Exercise 1: Relative Clauses Pseudo-Logical Form for the cat that John saw: Pseudo-Logical Form for the cat that John saw: np det the n cat lambda xs np vp vjohn sawx

7 Exercise 1: Relative Clauses Homework Question (A): Homework Question (A):  Modify the DCG to accept the omission of the complementizer that for object relative clauses  Your DCG should accept both of the following:  the cat John saw  the cat that John saw as NPs  Hint:  Write an empty category rule in place of the complementizer

8 Exercise 1: Relative Clauses Parsing complete sentences: Parsing complete sentences:  Run queries:  ?- s(X,[mary,hit,the,cat,that,john,saw],[]).  ?- s(X,[mary,hit,the,cat,that,saw,john],[]). Verify the DCG also (incorrectly) accepts as sentences: Verify the DCG also (incorrectly) accepts as sentences:  *Mary hit  *hit John  *hit

9 Exercise 1: Relative Clauses Multiple Embeddings Multiple Embeddings  Add rule  transitive_verb(v(hissed_at)) --> [hissed,at].  Turn on full printing (taken from Lecture 4)  ?- set_prolog_flag(toplevel_print_options,[max_depth(0)]).  Run query for  Mary hit the man that the cat that John saw hissed at

10 Exercise 1: Relative Clauses Homework Question (B): Homework Question (B):  The previous sentence  Mary hit the man that the cat that John saw hissed at has a doubly-embedded object relative clause structure:  Mary hit [ NP [ NP the man i ] that [ NP [ NP the cat j ] that John saw [ NP e j ]] hissed at [ NP e i ]]

11 Exercise 1: Relative Clauses Homework Question (B) contd.: Homework Question (B) contd.:  Without any further modification to the DCG, construct and show parses for:  A sentence with two levels of embedding using subject relative clauses  A sentence with two levels of embedding using one subject and one object relative clause  Any sentence with a triply-embedded relative clause structure  Notes:  i.e. you cannot add any rules or words to the DCG so far  The DCG only allows Det N sequences in relative clause constructions, i.e. you have to make do without NP -> Det N

12 Extra Credit Homework Question Answer for Exercise 1 Part (A) will also allow the complementizer to be dropped (incorrectly) for subject relative clauses: Answer for Exercise 1 Part (A) will also allow the complementizer to be dropped (incorrectly) for subject relative clauses:  the cat that saw John  *the cat saw John(as a complex NP)

13 Extra Credit Homework Question Modify the DCG to allow that to be omitted only in the case of object relative clauses, i.e. grammar should still accept: Modify the DCG to allow that to be omitted only in the case of object relative clauses, i.e. grammar should still accept:  the cat John saw but reject its subject relative clause counterpart:  *the cat saw John Hint (for one possible implementation): Hint (for one possible implementation):  Look at how subject/verb agreement was enforced

14 Exercise 2: Disjunctive Tree-Walker Tree-walker template (disjunctive form): Tree-walker template (disjunctive form):  visit(X) :-  X =.. [_,A1,_],  visit(A1).  visit(X) :-  X =.. [_,_,A2],  visit(A2).  visit(X) :-  X =.. [_,A],  visit(A).  visit(X) :- atom(X). Note: Note:  used underscores to substitute for variables that are only mentioned once

15 Exercise 2: Disjunctive Tree-Walker Let’s modify visit/1 to look for John only: Let’s modify visit/1 to look for John only:  visit(X) :-  X =.. [_,A1,_],  visit(A1).  visit(X) :-  X =.. [_,_,A2],  visit(A2).  visit(X) :-  X =.. [_,A],  visit(A).  visit(X) :- atom(X).<- to be substituted by -visit(john).

16 Exercise 2: Disjunctive Tree-Walker Consult visit/1 Consult visit/1  Make sure DCG is still loaded ?- listing. to check Turn on tracing for visit/1 only Turn on tracing for visit/1 only  ?- spy(visit/1). Run the query: Run the query:  ?- s(X,[mary,hit,the,cat,that,hissed,at,john],[]), visit(X).  Step through debugger using the command l (leap)  Prolog should succeed and report X.

17 Exercise 2: Disjunctive Tree-Walker Test the structures for sentences: Test the structures for sentences:  Mary hit the cat that hissed at Mary  Query should fail  John saw the cat that saw John  Query should succeed twice

18 Exercise 2: Disjunctive Tree-Walker Homework Question: Homework Question:  Modify visit/1 to search for all NP nodes  How many times should visit/1 succeed for the following sentence?  Mary hit the cat that hissed at John Hint: Hint:  You’ll need to add more than one clause to visit/1

19 Exercise 3: Collecting Answers Instead of entering ; (possibly repeated) to the Prolog interpreter … Instead of entering ; (possibly repeated) to the Prolog interpreter …  we can used a higher-order predicate findall/3 to collect together all possible answers to a query findall/3 findall/3  Prolog build-in  Usage:  findall(X,Query,List) X may be a variable or constant or structure bound once per successful call to QueryX may be a variable or constant or structure bound once per successful call to Query Query is the Prolog query we wish to test (minus ?- and.)Query is the Prolog query we wish to test (minus ?- and.) List is the collected list of values of X per successful callList is the collected list of values of X per successful call

20 Exercise 3: Collecting Answers Example: Example:  male(john).  male(pete).  female(mary).  female(jill).  human(X) :- female(X) ; male(X).( ; indicates disjunction) Prolog query: Prolog query:  ?- human(X).  X = mary ;  X = jill ;  X = john ;  X = pete ;  No

21 Exercise 3: Collecting Answers Using findall/3: Using findall/3:  ?- findall(X,human(X),List).  X = _G283(an internally generated variable)  List = [mary,jill,john,pete] ;  No length/2 length/2  Prolog built-in  Usage:  length(List,N) List is a listList is a list N is bound to the number of elements in ListN is bound to the number of elements in List Example: Example:  ?- findall(X,human(X),List), length(List,N).  N = 4

22 Exercise 3: Collecting Answers Basic (unmodified) disjunctive tree-walker: Basic (unmodified) disjunctive tree-walker:  visit(X) :-  X =.. [_,A1,_],  visit(A1).  visit(X) :-  X =.. [_,_,A2],  visit(A2).  visit(X) :-  X =.. [_,A],  visit(A).  visit(X) :- atom(X).

23 Exercise 3: Collecting Answers Homework Question: Homework Question:  Assuming the unmodified version of visit/1  What does the query  ?- s(X,[mary,hit,the,cat,that,hissed,at,john],[]), findall(once,visit(X),L), findall(once,visit(X),L), length(L,N). length(L,N).do?


Download ppt "LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG."

Similar presentations


Ads by Google