Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

2 Administrivia Reminder Reminder  Homework 2 due today  Last minute help?  This afternoon, 309 Douglass

3 Review Last time… Last time…  Introduced two new DCG features  Prolog code: { … }  Structures as non-terminals  As an illustration of the additional power provided by these features, we used them to convert: a + b + a + b +into a n b na n b n

4 Today’s Lecture We’re going to look at the use of these two features in more detail … We’re going to look at the use of these two features in more detail …  And, in the next set of computer laboratory exercises and homework, you’ll be using them to encode linguistic constraints

5 Non-terminals as structures Can be used to convert an acceptor into a parser Can be used to convert an acceptor into a parser  Example grammar:  s --> np, vp.  np --> pronoun.  np --> [the,ball].  pronoun --> [i].pronoun --> [we].  vp --> unergative.  vp --> transitive, np.  unergative --> [ran].  transitive --> [hit].  Accepts sentence:  I hit the ball

6 Non-terminals as structures However, the DCG version of the grammar is only an acceptor (Yes/No) However, the DCG version of the grammar is only an acceptor (Yes/No)  i.e.  ?- s([i,hit,the,ball],[]).  Yes

7 Non-terminals as structures We’d like to have the query return some representation of a parse tree: We’d like to have the query return some representation of a parse tree: s npvp vnp detn theball hit i

8 Non-terminals as structures Basic Idea: Basic Idea:  Add a variable for each (relevant) non- terminal that will be used to return the fragment of the parse tree for that non- terminal

9 Non-terminals as structures Adding a variable: Adding a variable:  s(X) --> np(Y), vp(Z).  np(X) --> pronoun(X).  np(X) --> [the,ball].  pronoun(X) --> [i].  pronoun(X) --> [we].  vp(X) --> unergative(X).  vp(X) --> transitive(Y), np(Z).  unergative(X) --> [ran].  transitive(X) --> [hit].

10 Non-terminals as structures Variable bindings: Variable bindings:  s(X) --> np(Y), vp(Z).X = s(Y,Z)  np(X) --> pronoun(Y).X = np(Y)  np(X) --> [the,ball].X = np(det(the),n(ball))  pronoun(X) --> [i].X = i  pronoun(X) --> [we].X = we  vp(X) --> unergative(Y).X = vp(Y)  vp(X) --> transitive(Y), np(Z).X = vp(Y,Z)  unergative(X) --> [ran].X = v(ran)  transitive(X) --> [hit].X = v(hit)

11 Non-terminals as structures Substituting: Substituting:  s(s(Y,Z)) --> np(Y), vp(Z).  np(np(Y)) --> pronoun(Y).  np(np(det(the),n(ball))) --> [the,ball].  pronoun(i) --> [i].  pronoun(we) --> [we].  vp(vp(Y)) --> unergative(Y).  vp(vp(Y,Z)) --> transitive(Y), np(Z).  unergative(v(ran)) --> [ran].  transitive(v(hit)) --> [hit].

12 Non-terminals as structures Translation into Prolog clausal form: Translation into Prolog clausal form:  s(s(Y,Z)) --> np(Y), vp(Z). s(s(Y, Z), L1, L3) :- np(Y,L1,L2), vp(Z, L2,L3).s(s(Y, Z), L1, L3) :- np(Y,L1,L2), vp(Z, L2,L3).  np(np(Y)) --> pronoun(Y). np(np(Y), L1, L2) :- pronoun(Y,L1,L2).np(np(Y), L1, L2) :- pronoun(Y,L1,L2).  np(np(det(the),n(ball))) --> [the,ball]. np(np(det(the), n(ball)), [the, ball|L], L).np(np(det(the), n(ball)), [the, ball|L], L).  pronoun(i) --> [i]. pronoun(i, [i|L], L).pronoun(i, [i|L], L). Note: Note:  In s/3, the 1 st argument is the extra parameter we added to the gtrammar.  2 nd and 3 rd arguments represent the difference list

13 Non-terminals as structures Translation into Prolog clausal form contd.: Translation into Prolog clausal form contd.:  pronoun(we) --> [we]. pronoun(we, [we|L], L).pronoun(we, [we|L], L).  vp(vp(Y)) --> unergative(Y). vp(vp(Y), L1, L2) :- unergative(Y,L1,L2).vp(vp(Y), L1, L2) :- unergative(Y,L1,L2).  vp(vp(Y,Z)) --> transitive(Y), np(Z). vp(vp(Y,Z), L1, L3) :- transitive(Y,L1,L2), np(Z,L2,L3).vp(vp(Y,Z), L1, L3) :- transitive(Y,L1,L2), np(Z,L2,L3).  unergative(v(ran)) --> [ran]. unergative(v(ran), [ran|L], L).unergative(v(ran), [ran|L], L).  transitive(v(hit)) --> [hit]. transitive(v(hit), [hit|L], L).transitive(v(hit), [hit|L], L).

14 Retrieving Parses Prolog query Prolog query  ?- s(X,[i,hit,the,ball],[]).  Note: X precedes difference listX precedes difference list Response: Response:  X = s(np(i),vp(v(hit),np(det(the),n(ball))))

15 DCG more powerful than Context-Free In Lecture 9, there was a promissory note… In Lecture 9, there was a promissory note…  We can write a DCG for the context- sensitive language L abc = { a n b n c n | n >= 1 } (which cannot be encoded by any context- free grammar)

16 DCG more powerful than Context-Free Basic Idea: Basic Idea:  Same trick for converting a + b + into a n b n 1. Modify non-terminals to pass around a counter 2. Increment and decrement counter to keep track of the number of as and bs

17 DCG more powerful than Context-Free We already know we can write a context- free grammar that keeps track of 2 things at a time We already know we can write a context- free grammar that keeps track of 2 things at a time  Let’s start by writing a grammar for a n b + c n (which happens to be a context-free language)

18 DCG more powerful than Context-Free L(G n+n ) = { a n b + c n | n >= 1 } L(G n+n ) = { a n b + c n | n >= 1 }  Rules:  S -> aTc  T -> aTc  This will generate an equal number of as and cs  Note:  Need S and T to avoid generating bs only, see later…

19 DCG more powerful than Context-Free Add rules for U: Add rules for U:  S -> aTc  T -> aTc  T -> U  U -> b U  U -> b  Rules for non-terminal U will guarantee the generation of one or more bs

20 DCG more powerful than Context-Free Convert grammar into DCG rules: Convert grammar into DCG rules:  s --> [a],t,[c].  t --> [a],t,[c].  t --> u.  u --> [b],u.  u --> [b].

21 DCG more powerful than Context-Free Add a variable for the counter we need: Add a variable for the counter we need:  s --> [a],t(N),[c].  t(N) --> [a],t(M),[c].  t(N) --> u(M).  u(N) --> [b],u(M).  u(N) --> [b].

22 DCG more powerful than Context-Free Determine the correct counter values: Determine the correct counter values:  s --> [a],t(N),[c].N=1  t(N) --> [a],t(M),[c].M is N+1  t(N) --> u(M).M=N  u(N) --> [b],u(M). N>1, M is N-1  u(N) --> [b].N=1 Note: Note:  N>1 condition required to prevent grammar from decrementing counter below 1

23 DCG more powerful than Context-Free Substitute values and insert Prolog code: Substitute values and insert Prolog code:  s --> [a],t(1),[c].  t(N) --> [a],{M is N+1},t(M),[c].  t(N) --> u(N).  u(N) --> {N>1}, [b],{M is N-1},u(M).  u(1) --> [b].

24 DCG more powerful than Context-Free Sample Prolog queries: Sample Prolog queries:  ?- s([a,a,b,b,c,c],[]).  Yes  ?- s([a,a,b,b,c],[]).  No  ?- s([a,a,b,b,b,c,c],[]).  No  ?- s([a,a,b,c,c],[]).  No


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

Similar presentations


Ads by Google