LING 388 Language and Computers Lecture 16 10/23/03 Sandiway FONG.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 8 – Search and conclusions.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
Review of Homework 4 November 20, Exercise 1 (A) 1 pt Modify the DCG to accept the omission of the complementizer that for object relative clauses.
November 2008NLP1 Natural Language Processing Definite Clause Grammars.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
11/10/04 AIPP Lecture 6: Built-in Predicates1 Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
A problem with functions: arguments must always have values that can be worked out Whenever we call a function we give it arguments. Lisp then works out.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
LING 388 Language and Computers Lecture 2 9/04/03 Sandiway FONG.
LING 388 Language and Computers Lecture 19 11/04/03 Sandiway FONG.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
LING 364: Introduction to Formal Semantics
LING 388 Language and Computers Lecture 14 10/16/03 Sandiway FONG.
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/25.
Inference and Resolution for Problem Solving
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
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 Lecture 10 10/2/03 Sandiway FONG.
LING 388 Language and Computers Take-Home Final Examination 12/9/03 Sandiway FONG.
LING 388 Language and Computers Lecture 20 11/6/03 Sandiway FONG.
LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25.
LING 388 Language and Computers Lecture 9 9/30/03 Sandiway FONG.
Lesson 6. Refinement of the Operator Model This page describes formally how we refine Figure 2.5 into a more detailed model so that we can connect it.
LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG.
LING 388 Language and Computers Lecture 17 10/28/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
LING 388 Language and Computers Lecture 12 10/9/03 Sandiway FONG.
LING 388 Language and Computers Lecture 6 9/18/03 Sandiway FONG.
LING 388 Language and Computers Lecture 15 10/21/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 8.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.
LING 388: Language and Computers Sandiway Fong Lecture 17.
Formal Models of Computation Part II The Logic Model
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
LING 388: Language and Computers Sandiway Fong Lecture 4.
LING 388: Language and Computers Sandiway Fong Lecture 7.
CS 321 Programming Languages and Compilers Prolog part 2.
CS 403: Programming Languages Lecture 19 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
CSC 270 – Survey of Programming Languages Prolog Lecture 2 – Unification and Proof Search.
1 Knowledge Based Systems (CM0377) Lecture 3 (Last modified 5th February 2001)
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
CSC 221: Recursion. Recursion: Definition Function that solves a problem by relying on itself to compute the correct solution for a smaller version of.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
Prolog Program Style (ch. 8) Many style issues are applicable to any program in any language. Many style issues are applicable to any program in any language.
Rules Statements about objects and their relationships Expess ◦ If-then conditions  I use an umbrella if there is a rain  use(i, umbrella) :- occur(rain).
Negation Chapter 5. Stating Negative Conditions n Sometimes you want to say that some condition does not hold n Prolog allows this –not/1this is a predicate.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Prolog 3 Tests and Backtracking 1. Arithmetic Operators Operators for arithmetic and value comparisons are built-in to Prolog = always accessible / don’t.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.
COP4020 Programming Languages Logic Programming Prof. Xin Yuan.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
More on Prolog syntax Already seen program statement types: Already seen program statement types: rules: p(X) :- q(X,Y), r(Y,z). rules: p(X) :- q(X,Y),
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
Tests, Backtracking, and Recursion
Presentation transcript:

LING 388 Language and Computers Lecture 16 10/23/03 Sandiway FONG

Administrivia

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

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)

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

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

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

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

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

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))) ?

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

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

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

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).

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

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

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

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

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

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

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

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

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

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