Download presentation
Presentation is loading. Please wait.
1
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25
2
Administrivia homework 3 –deadline is today
3
Last Time Limits of Finite State Technology –different kinds of infinity one reduces to looping, the other doesn’t aaabbb b b b anbnanbn s1s1 s2s2 s3s3 ba s1s1 s2s2 s3s3 aa s4s4 b s1s1 s2s2 s3s3 ba s4s4 b s1s1 s2s2 s3s3 aa s4s4 b s5s5 b s1s1 s2s2 s3s3 aa s4s4 a s5s5 b s1s1 s2s2 s3s3 ba s4s4 b s5s5 b a+b+a+b+
4
Last Time Distance and Finite State Memory (Miller and Chomsky 1963) –The people/person who called and wanted to rent your house when you go away next year are/is from California –need “memory” –14 words separating people from are from (Coleman 2005)
5
Today’s Topic back to writing grammars... –building sentence meaning –next step towards our translator we ’ re gonna need the ability to call Prolog predicates from DCG rules –we can insert calls to any Prolog predicate on the RHS of DCG rules using curly braces –{ … }
6
Predicate-Argument Structure example –i hit the ball currently, we produce parse tree representations of the form –?- s(P, [i,hit,the,ball], []). –P = s(np(i),vp(v(hit),np(det(the),n(ball)))) suppose, we want instead to produce predicate-argument structure like –?- s(P, [i,hit,the,ball], []). –P = hit(i,ball) –hit = predicate, arguments are i and ball predicate-argument structure –a simpler representation of the sentence than a parse tree –abstraction of the parse tree representation e.g. by picking out only the content word heads of each phrase
7
Predicate-Argument Structure grammar rule – s(s(X,Y)) --> np(X), vp(Y). X = np(i) Y = vp(v(hit),np(det(the),n(ball))) revised grammar rule –s(PA) --> np(X), vp(Y), { PrologCode }. –to be read as: s rewrites to np followed by vp followed by PrologCode idea –write some Prolog code –call PrologCode from grammar to pick out the predicate hit and its two arguments –and compute PA such that PA = hit(i,ball)
8
Predicate-Argument Structure head-of relation –linguistic concept –examples head of the noun phrase np(det(the),n(ball)) is the noun ball head of the verb phrase vp(v(hit),np(det(the),n(ball))) is the verb hit head of the noun phrase np(i) is the noun i head-of/2 relation in Prolog –headof(TreeFragment,Head) –headof(np(_,n(N)),N). –headof(vp(v(V),_),V). –headof(np(N),N). example query –?- headof(vp(v(hit),np(det(the),n(ball))),H). H = hit
9
Predicate-Argument Structure grammar rule –s(s(X,Y)) --> np(X), vp(Y). X = np(i) Y = vp(v(hit),np(det(the),n(ball))) revised grammar rule –s(PA) --> np(X), vp(Y), { PrologCode }. –headof(np(_,n(N)),N). –headof(vp(v(V),_),V). –headof(np(N),N). idea –connect PrologCode to headof –i.e. make the grammar rule for s call predicate headof/2 to extract phrase heads to compute PA = hit(i,ball)
10
Predicate-Argument Structure revised grammar rule –s(PA) --> np(X), vp(Y), { predarg(X,Y,PA) }. –headof(np(_,n(N)),N). –headof(vp(v(V),_),V). –headof(np(N),N). connecting code –predarg(X,Y,PA) :- headof(X,S), headof(Y,P), Y=vp(_,NP), headof(NP,O), PA =.. [P,S,O]. built-in predicate univ =.. a(b) =.. [a,b]. a(b,c) =.. [a,b,c]. X = np(i) Y = vp(v(hit),np(det(the),n(ball)))
11
Predicate-Argument Structure instead of we get the simpler (nonterminal-free) reduced form hit(i,ball) s npvp vnp detn the ball hit i i ball
12
Predicate-Argument Structure looking ahead... Predicate-argument mapping from language to language –simpler mapping than parse tree to parse tree because languages may differ greatly with respect to construction format and word order Example 1 (Declarative case): –John bought a book bought(john,book) –Taroo-ga hon-o katta katta(taroo,hon) Example 2 (Subject wh-Question): –Who bought a book bought(who,book) –dare-ga hon-o katta ka katta(dare,hon) Example 3 (Object wh-Question): –What did John buy bought(john,what) –taroo-ga nani-o katta ka katta(taroo,nani)
13
More applications let’s look at another application of calls to Prolog using { } the following example illustrates the power of out-calls to Prolog predicates
14
Non-regular language a n b n revisited last time we mentioned –a n b n is not a regular language that is, we can ’ t write a grammar for it using regular grammar rules (or a FSA or a regular expression) recall that regular grammar rules must either be in left or right recursive form however, a grammar with both left and right recursive rules can accept it –a --> [a], b. –b --> [b]. –b --> a, [b]. grammar accepts –aabb aaaabbbb and rejects –*aab *aaaabbbbb B A b a A B A b a
15
DCG and Chomsky Hierarchy Regular Grammars = Type-3 FSA Regular Expressions DCG = Type-0 Type-2 Type-1
16
Non-regular language a n b n revisited there is another way… idea –we know we can write a regular grammar for some a’s followed by some b’s –we just can’t force the number of a’s and b’s to match up –That grammar is G ab such that L(G ab ) = a + b + –s --> [a], b. –b --> [a], b. –b --> [b], c. –b --> [b]. –c --> [b], c. –c --> [b].
17
From a + b + to a n b n idea: add an extra argument as a counter to count the number of a s and b s the extra argument is used as memory here (not permitted under regular grammar rules) Input stringCounter Value a1 aa2 aaa3 aaab 2 aaabb 1 aaabbb 0 so –every time we see an a, we add 1 to the counter –every time we see a b, we subtract 1 from the counter this way we can be sure the numbers of as and bs match
18
From a + b + to a n b n implementation –add an extra argument to the non-terminals to count the number of a s and b s s --> [a], b(1).1 means we have seen one a b(N) --> [a], b(M). where M is N+1 b(N) --> [b], c(M). where M is N-1 b(N) --> [b].N must be 1 c(N) --> [b], c(M). where M is N-1 c(N) --> [b].N must be 1
19
From a + b + to a n b n DCG rules –s --> [a], b.s --> [a], b(1). –b --> [a], b.b(N) --> [a], {M is N+1}, b(M). –b --> [b], c.b(N) --> [b], {M is N-1}, c(M). –b --> [b].b(1) --> [b]. –c --> [b], c.c(N) --> [b], {M is N-1}, c(M). –c --> [b].c(1) --> [b]. Prolog built-in is/2 ?- X is 4-1 X = 3
20
From a + b + to a n b n Computation Tree: –?- s([a,a,b,b], []). –?- b(1,[a,b,b], []). –?- b(2,[b,b], []). –?- c(1,[b], []). –Yes Computation Tree: –?- s([a,a,b], []). –?- b(1,[a,b], []). –?- b(2,[b], []). –?- c(1,[], []). –No 1.s --> [a], b(1). 2.b(N) --> [a], {M is N+1}, b(M). 3.b(N) --> [b], {M is N-1}, c(M). 4.b(1) --> [b]. 5.c(N) --> [b], {M is N-1}, c(M). 6.c(1) --> [b].
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.