Download presentation
Presentation is loading. Please wait.
1
LING 388 Language and Computers Lecture 16 10/23/03 Sandiway FONG
2
Administrivia
3
Review Last time, we discussed how to implement the filter: Last time, we discussed how to implement the filter: All variables must be bound by an operator ( x) To block examples like: *John hits(np(john),vp(v(hit),np(x))) Implementation: Implementation: Based on a tree-walker (disjunctive form) that searched and returned true if a variable np(x) and an accompanying operator x could be found in phrase structure
4
Review: Disjunctive Tree-Walker variable(np(x)). variable(X) :- X =.. [F,A1,A2], variable(A1). variable(X) :- X =.. [F,A1,A2], variable(A2). variable(X) :- X =.. [F,A], variable(A). Given some tree structure X: variable(X) holds if there is some np(x) in X Clause by clause: 1.Matches np(x) (and stops) 2.Recursively calls variable(A1) when X is of form F(A1,A2) 3.Recursively calls variable(A2) when X is of form F(A1,A2) 4.Recursively calls variable(A) when X is of form F(A)
5
Review: Disjunctive Tree-Walker variable(np(x)). variable(X) :- X =.. [F,A1,A2], variable(A1). variable(X) :- X =.. [F,A1,A2], variable(A2). variable(X) :- X =.. [F,A], variable(A). Notes: 1. Every clause for variable/1 except for the first recursively calls variable/1 on a subtree 2.Only way variable/1 can terminate and succeed is if it terminates in the 1st clause
6
Review: Disjunctive Tree-Walker Worked example for *John hit [ NP e] Worked example for *John hit [ NP e] Prolog query: Prolog query: ?- variable(s(np(john),vp(v(hit),np(x)))). s npvp vnp x hit john
7
Review: Disjunctive Tree-Walker variable(np(x)). variable(X) :- X =.. [F,A1,A2], variable(A1). variable(X) :- X =.. [F,A1,A2], variable(A2). variable(X) :- X =.. [F,A], variable(A). Example of derivation: ?- variable(s(np(john),vp(v(hit),np(x)))). ?- variable(np(john)) ?- variable(john). FAILS ?- variable(vp(v(hit),np(x))). ?- variable(v(hit)). ?- variable(hit). FAILS ?- variable(np(x)). SUCCEEDS Note: ?- variable(s(np(john),vp(v(hit),np(mary)))). FAILS ?-variable ( np(np(det(the),n(cat)),lambda(x,s(np(i),vp( v(saw),np(x)))))). SUCCEEDS
8
Review: Disjunctive Tree-Walker Operator/1 is a x, i.e. lambda(x,_), in the phrase structure Operator/1 is a x, i.e. lambda(x,_), in the phrase structure operator(lambda(x,_)). operator(X) :- X =.. [F,A1,A2], operator(A1). operator(X) :- X =.. [F,A1,A2], operator(A2). operator(X) :- X =.. [F,A], operator(A). Examples: ?- operator(s(np(john),vp(v(hit),np(x)))).?- operator(s(np(john),vp(v(hit),np(x)))). NoNo ?- operator(s(np(john),vp(v(hit),np(mary)))).?- operator(s(np(john),vp(v(hit),np(mary)))). NoNo ?-operator ( np(np(det(the),n(cat)),?-operator ( np(np(det(the),n(cat)),lambda(x,s(np(i),vp(v(saw),np(x)))))). YesYes
9
Review: Filter Implementation Filter: Filter: All variables must be bound by an operator ( x) Implementation (Initial try) : Implementation (Initial try) : Using predicates: variable(X)np(x) finder operator(X)lambda(x, … ) finder Define: filter(X) :- variable(X) -> operator(X). To be read as: filter(X) holds if operator(X) holds when variable(X) holdsfilter(X) holds if operator(X) holds when variable(X) holds Note: -> is the Prolog built-in “if … then” construct
10
Review: Filter Implementation Use : Use : ?- s(X,Sentence,[]), filter(X). X is the phrase structure returned by the DCG Sentence is the input sentence encoded as a list Problem with definition: Problem with definition: filter(X) :- variable(X) -> operator(X). Semantics: Holds if there is some variable that has an accompanying operator Question: What happens if we have two variables only one of which is properly bound? Example: filter(X) fails to exclude … *the cat that I saw hit *the cat that I saw [ NP e] hit [ NP e] s(np(np(det(the),n(cat)),lambda(x,s(np(i),vp(v(saw),np(x))))),vp(v(hit),np(x))) s(np(np(det(the),n(cat)),lambda(x,s(np(i),vp(v(saw),np(x))))),vp(v(hit),np(x))) ?
11
Filter Implementation: Part 2 A better (i.e. more faithful) implementation… A better (i.e. more faithful) implementation… When we find np(x), we check nodes dominating np(x) for signs of x If we find lambda, we know np(x) is bound by that operator Implementation Question: Implementation Question: We know predicate variable/1 finds np(x) How do we modify it to report when it finds lambda as well? lambda(x, … ) np(x) s lambda x variable/1 true
12
Filter Implementation: Part 2 Idea: Idea: Modify predicate variable/1 to produce a sign of some sort if it sees a lambda on the way down to np(x) Note: if lambda doesn’t dominate np(x), we don’t want a sign Use the extra argument mechanism from previous lectures for feature passing (person/number agreement) We’ll pass an arbitrary feature, call it f, if we see an appropriate lambda lambda(x, … ) np(x) s lambda x variable(X,F) true F unbound F = f
13
Filter Implementation: Part 2 variable(np(x)). variable(X) :- X =.. [F,A1,A2], variable(A1). variable(X) :- X =.. [F,A1,A2], variable(A2). variable(X) :- X =.. [F,A], variable(A). variable(np(x),_). variable(X,F) :- X =.. [_,A1,A2], variable(A1,F). variable(X,F) :- X =.. [_,A1,A2], variable(A2,F). variable(X,F) :- X =.. [_,A], variable(A,F). We need to modify variable/1 so that we can pass information indicating the presence or absence of lambda as we traverse the tree We do this by first adding a 2nd argument F to variable/1
14
Filter Implementation: Part 2 variable(np(x),_). variable(lambda(x,Y),f) :- variable(Y,_). variable(X,F) :- X =.. [_,A1,A2], variable(A1,F). variable(X,F) :- X =.. [_,A1,A2], variable(A2,F). variable(X,F) :- X =.. [_,A], variable(A,F). step 2: add a clause to detect and report the presence of lambda variable(np(x),_). variable(X,F) :- X =.. [_,A1,A2], variable(A1,F). variable(X,F) :- X =.. [_,A1,A2], variable(A2,F). variable(X,F) :- X =.. [_,A], variable(A,F).
15
Filter Implementation: Part 2 variable(np(x),_). variable(lambda(x,Y),f) :- variable(Y,_). variable(X,F) :- X =.. [_,A1,A2], variable(A1,F). variable(X,F) :- X =.. [_,A1,A2], variable(A2,F). variable(X,F) :- X =.. [_,A], variable(A,F). Notes: 1.Every clause for variable/2 except for the first one recursively calls variable/2 on a subtree Only way variable/2 can succeed is if it terminates in the 1st clause 2.When variable/2 holds, we can inspect the 2nd argument to see if along the way it found a lambda expression as well This is signaled by the f feature The 2nd clause exclusively sets the 2nd argument
16
Filter Implementation: Part 2 np(x) s lambda x x variable(np(x),_). variable(lambda(x,Y),f) :- variable(Y,_). variable(X,F) :- X =.. [_,A1,A2], variable(A1,F). variable(X,F) :- X =.. [_,A1,A2], variable(A2,F). variable(X,F) :- X =.. [_,A], variable(A,F). Underscore (don’t care variable) because we’re not interested in reporting multiple lambdas dominating np(x) sets 2nd argument to be f
17
Filter Implementation: Part 2 variable(np(x),_). variable(lambda(x,Y),f) :- variable(Y,_). variable(X,F) :- X =.. [Y,A1,A2], \+ Y = lambda, variable(A1,F). variable(X,F) :- X =.. [Y,A1,A2], \+ Y = lambda, variable(A2,F). variable(X,F) :- X =.. [_,A], variable(A,F). Since clause 2 must set f exclusively, we must prevent lambda from matching these two clauses
18
Filter Implementation: Part 2 Use: Use: filter(X) :- variable(X,F), F == f. Note: Note: Filter/1 holds if variable/2 holds and the value reported in the 2nd argument F is identical to f We use identity (==) instead of unification (=) because we’re testing whether F has been bound to a value
19
Identity (==) == == is a Prolog built-in taking two arguments compares but does not perform unification Note: = attempts to unify its arguments= attempts to unify its arguments Hence, neither of the clausesHence, neither of the clauses –filter(X) :- variable(X,F), F = f. –filter(X) :- variable(X,f). will work for our purposes Examples: ?- abc == abc.Yes?- abc = abc.Yes ?- X == abc.No?- X = abc.Yes ?- X = abc, X == abc.Yes?- X = abc, X = abc. Yes ?- X == Y.No?- X == Y.Yes
20
Filter Implementation: Part 3 Definition: Definition: filter(X) :- variable(X,F), F == f. Is still not quite right … Is still not quite right … filter(X) holds if there exists one valid variable/lambda pair in X However … However … This fails to block the case where there may be more than one variable, only one of which has a valid accompanying lambda expression, as in: *the cat that I saw hit s(np(np(det(the),n(cat)),lambda(x,s(np(i),vp(v(saw),np(x))))), vp(v(hit),np(x))) vp(v(hit),np(x))) In other words, variable/1 is true for the whole expression because it finds the lambda/np(x) pair
21
Filter Implementation: Part 3 Solution: Solution: Want filter/1 to hold if there are no configurations for which variable(X,F) holds and F remains unbound New Definition: New Definition: filter(X) :- \+ ( variable(X,F), var(F) ). to be read as: filter(X) holds if it’s not the case that when variable(X,F) succeeds and F is uninstantiated Note: Note: var(F) is a Prolog built-in that holds if F is uninstantiated, i.e. a Prolog variable
22
var/1 var(X) var(X) is a Prolog built-in that takes one argument holds if X is a variable at the time of the call to var/1 Examples: Examples: ?- var(X).Yes ?- var(f).No ?- X=f, var(X).No ?- var(X), X = 2.Yes … fact that X is no longer a variable after unifying with 2 doesn’t change the semantics of var/1
23
Summary: Filter Implementation Summarizing: Summarizing: filter(X) :- \+ ( variable(X,F), var(F) ) implements filter: All variables must be bound by an operator ( x) variable(X,F) variable(X,F) is a disjunctive tree-walker that looks for np(x) also looks for lambda(x,Y) where Y contains a variable np(x) returns f as the value of F if it finds the lambda above variable(X,F), var(F) variable(X,F), var(F) will succeed if there is an np(x) without an accompanying lambda expression \+ ( variable(X,F), var(F) ) \+ ( variable(X,F), var(F) ) will succeed if there aren’t any np(x)s without an accompanying lambda expression
24
Next Time … We’ll look at how to implement the other constraint mentioned in Lecture 14: We’ll look at how to implement the other constraint mentioned in Lecture 14: All variables must be bound by an operator ( x) Operator ( x) can only bind one variable
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.