Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 388 Language and Computers Lecture 20 11/6/03 Sandiway FONG.

Similar presentations


Presentation on theme: "LING 388 Language and Computers Lecture 20 11/6/03 Sandiway FONG."— Presentation transcript:

1 LING 388 Language and Computers Lecture 20 11/6/03 Sandiway FONG

2 Administrivia Next Tuesday (11th) Next Tuesday (11th)  Veterans’ Day Today’s Lecture Today’s Lecture  Homework 3 review  Help with Homework 4 Next time … Next time …  We start a brand-new topic known as Shallow Parsing  We’ll begin with Part-of-speech (POS) tagging, stemming …

3 Homework 3 Review

4 Exercise 1 Part (B): Encoding the idiom kick the bucket Add a DCG rule to encode the idiomatic meaning of John kicked the bucket, i.e. Add a DCG rule to encode the idiomatic meaning of John kicked the bucket, i.e. s npvp v died john ?- s(X,[john,kicked,the,bucket],[]) X = s(np(john),vp(v(died)))  Hint: see how the terminal string the ball was encoded in Lecture 10 np --> [the,ball].

5 Sample DCG  s(s(X,Y)) --> np(X), vp(Y).  np(np(X,Y)) --> det(X,Num), common_noun(Y,Num).  np(np(X)) --> proper_noun(X).  vp(vp(X)) --> intransitive_verb(X).  vp(vp(X,Y)) --> transitive_verb(X), np(Y).  common_noun(n(man),sg) --> [man].  common_noun(n(men),sg) --> [men].  proper_noun(john) --> [john].  det(det(the),_) --> [the]. det(det(a),sg) --> [a].  intransitive_verb(v(ran)) --> [ran].  transitive_verb(v(saw)) --> [saw].

6 Exercise 4 Part (A): Implementing every and some Want parses: Want parses:  s(forall(X,man(X)),vp(v(likes),np(john))))  s(exists(X,men(X)),vp(v(like),np(n(beer)))) for for  Every man likes John  Some men like beer

7 Exercise 4 Part (A): Implementing every and some  NP rules:  np(np(X,Y)) --> quantifier(X,Num), common_noun(Y,Num).  quantifier(q(every),sg) --> [every].  quantifier(q(some),_) --> [some].  common_noun(n(man),sg) --> [man].  common_noun(n(men),pl) --> [men]. Solution: Solution:  Write one rule specialized for every and another for some

8 Exercise 4 Part (A): Implementing every and some  Case 1: every  np(np(X,Y)) --> quantifier(X,Num), common_noun(Y,Num).  quantifier(q(every),sg) --> [every].  common_noun(n(man),sg) --> [man]. Parsing every man will produce the following series of variable bindings: Parsing every man will produce the following series of variable bindings: np(np(X,Y)) --> quantifier(X,Num), common_noun(Y,Num). quantifier(q(every),sg)common_noun(n(man),sg) everyman

9 Exercise 4 Part (A): Implementing every and some  Perform a partial substitution; instantiate every:  np(np(X,Y)) -->  quantifier(q(every),Num),  common_noun(n(N),Num). Note: Note:  NP rule is now particular to sequences every N  I.e. NP rule won’t fire for other NP sequences like:  some men  the cat  John

10 Exercise 4 Part (A): Implementing every and some  Substitute forall for np:  np(forall(X,Y)) -->  quantifier(q(every),Num),  common_noun(n(N),Num). Finally, add code in {…} to generate Y from N: Finally, add code in {…} to generate Y from N:  np(forall(X,Y)) -->  quantifier(q(every),Num),  common_noun(n(N),Num),  {Y=..[N,X]}. The same implementation strategy works also for some and exists(X,N(X)) … The same implementation strategy works also for some and exists(X,N(X)) …

11 Key Concepts 1.Use partial variable substitution  … to customize a rule 2.We can build f(X) where f cannot be determined statically, i.e. at the time we specify the grammar rule by … by …  using Prolog built-in univ (=..), and  the DCG rule out-call mechanism {…}

12 Homework 4 Concepts

13 Logic and Negation in Prolog Filter 1: Filter 1:  All variables must be bound by an operator Implementation: Implementation:  \+ (variable(X,F), var(F))  variable/2 is an np(x) finder  F bound when x can be found Question: Question:  Why are we implementing a positive condition using negation (\+)?

14 Logic and Negation in Prolog np det the n cat lambda xs np vp vjohn sawx np vp v hissed atx s *The cat that John saw hissed at *The cat that John saw hissed at

15 Logic and Negation in Prolog Example: Example:  All tomatoes are red Define predicates: Define predicates:tomato(X)red(X) Condition: Condition:  ?- tomato(X), red(X).  holds if there exists some X such that X is a tomato and X is red  Doesn’t check all the tomatoes in the box  Hence, query does not guarantee that all the tomatoes in the box are red

16 Logic and Negation in Prolog Example: Example:  All tomatoes are red Equivalent condition: Equivalent condition:  It cannot be the case that there exists some tomato and that tomato is not red Implementation: Implementation:  ?- \+ ( tomato(X), \+ red(X)).  holds if it is not the case that there exists some X such that X is a tomato and X is not red  Guarantees that all the tomatoes in the box are red

17 Logic and Negation in Prolog Basic Quantifier Conversion Rules: Basic Quantifier Conversion Rules:   x p(x)  x  p(x)   x p(x)  x  p(x)  Examples:   X tomato(X), red(X)   X tomato(X), \+ red(X)  Prolog variables?  By default, existentially quantified ( 

18 Logic and Negation in Prolog Filter 1: Filter 1:  All variables must be bound by an operator Conversion: Conversion:  There must not exist a variable that is not bound by an operator Implementation: Implementation:  \+ (variable(X,F), var(F))  variable/2 is an np(x) finder  F bound when x can be found

19 Implementing the Exactly One Condition In Exercise 5 … In Exercise 5 …  Filter 2:  All operators must bind exactly one variable  Implementation:  filter2(X) :- operator(X).  Predicate:  operator(X) holds if X contains a x.Y with less than two variables in Yholds if X contains a x.Y with less than two variables in Y

20 Implementing the Exactly One Condition  Operator/1 calls predicate lt2vars/2:  lt2vars(X,F) holds if there are less than two variables in Xholds if there are less than two variables in X F is bound to one if there is one variable in XF is bound to one if there is one variable in X  We’ll need to impose either that: F == one or F == one or \+ var(F)\+ var(F) to the output of lt2vars/2 to implement the condition for exactly one variable to the output of lt2vars/2 to implement the condition for exactly one variable

21 Implementing the Universally Quantified Condition Not done yet … Not done yet …  Filter 2:  All operators must bind exactly one variable  Implementation:  filter2(X) :- operator(X).  Predicate:  operator(X) holds if X contains a x.Y with less than two variables in Yholds if X contains a x.Y with less than two variables in Y I.e. if in X  x.Y with less than two variables in YI.e. if in X  x.Y with less than two variables in Y

22 Implementing the Universally Quantified Condition Filter 2: Filter 2:  All operators must bind exactly one variable So we must convert this to an existentially quantified condition So we must convert this to an existentially quantified condition Equivalently: Equivalently:  In X, it cannot be the case that operator(X) holds and the number of variables bound is not one

23 Overlapping/Non-Overlapping Clauses Question: Question:  For tree-walkers, why do we sometimes want overlapping clauses, i.e. have more than one applicable clause, and why sometimes we don’t? Example: Example:  operator/1 is overlapping  lt2vars/2 is non-overlapping

24 Case 1: Non-Overlapping Clauses  lt2vars(np(x),F) :-  var(F), F = one.  lt2vars(X,F) :-  X =.. [_,A1,A2],  lt2vars(A1,F),  lt2vars(A2,F).  lt2vars(X,F) :-  \+ X = np(x),  X =.. [_,A],  lt2vars(A,F).  lt2vars(X,_) :- atom(X). np(x) Unary branching structure: Unary branching structure: matches two clauses blocks np(x) Want only one match!

25 Case 1: Non-Overlapping Clauses np(x) Need to block the lower clause from applying Need to block the lower clause from applying it does not set F, and otherwise it does not set F, and otherwise ?- lt2vars(X,F), var(F). will succeed when X has, say, three np(x)s [Upper clause will reject 3 np(x)s, but lower clause will pass it.]  lt2vars(np(x),F) :-  var(F), F = one.  lt2vars(X,F) :-  X =.. [_,A1,A2],  lt2vars(A1,F),  lt2vars(A2,F).  lt2vars(X,F) :-  \+ X = np(x),  X =.. [_,A],  lt2vars(A,F).  lt2vars(X,_) :- atom(X).

26 Case 2: Overlapping Clauses  operator(lambda(x,Y)):-  lt2vars(Y,_).  operator(X) :-  X =.. [_,A1,_],  operator(A1).  operator(X) :-  X =.. [_,_,A2],  operator(A2).  operator(X) :-  X =.. [F,A],  operator(A). lambda(x,_) Binary branching structure: Binary branching structure: matches three clauses Want multiple matches!

27 Case 2: Overlapping Clauses  operator(lambda(x,Y)):-  lt2vars(Y,_).  operator(X) :-  X =.. [_,A1,_],  operator(A1).  operator(X) :-  X =.. [_,_,A2],  operator(A2).  operator(X) :-  X =.. [F,A],  operator(A). lambda(x,_) operator/1 is a x finder We want it to be able to find and test all x structures within a phrase structure We want it to be able to find and test all x structures within a phrase structure ?- operator(X). will succeed once for each x in X ?- operator(X). will succeed once for each x in X

28 np det the n cat lambda xs np vp vjohn sawmary np vp v hissed atx lambda xs *Mary hit the man that the cat that John saw Mary hissed at *Mary hit the man that the cat that John saw Mary hissed at Case 2 np det the n man vp v hit s np mary first x

29 np det the n cat lambda xs np vp vjohn sawmary np vp v hissed atx lambda xs *Mary hit the man that the cat that John saw Mary hissed at *Mary hit the man that the cat that John saw Mary hissed at Case 2 np det the n man vp v hit s np mary first x

30 Key Concept We need to restrict or use overlap as appropriate We need to restrict or use overlap as appropriate  Because of Prolog’s search strategy  i.e. if a clause fails during a query, Prolog will look for another way to succeed


Download ppt "LING 388 Language and Computers Lecture 20 11/6/03 Sandiway FONG."

Similar presentations


Ads by Google