1 / 24

LING 388 Language and Computers

LING 388 Language and Computers. Lecture 10 10/2 /03 Sandiway FONG. Administrivia. Reminder Homework 2 due today Last minute help? This afternoon, 309 Douglass. Review. Last time… Introduced two new DCG features Prolog code: { … } Structures as non-terminals

Télécharger la présentation

LING 388 Language and Computers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Administrivia • Reminder • Homework 2 due today • Last minute help? • This afternoon, 309 Douglass

  3. Review • 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+ into • anbn

  4. Today’s Lecture • 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 • 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) • 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: s np vp v np i det n hit the ball

  8. Non-terminals as structures • 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: • 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: • 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: • 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: • s(s(Y,Z)) --> np(Y), vp(Z). • 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(det(the),n(ball))) --> [the,ball]. • np(np(det(the), n(ball)), [the, ball|L], L). • pronoun(i) --> [i]. • pronoun(i, [i|L], L). • Note: • In s/3, the 1st argument is the extra parameter we added to the gtrammar. • 2nd and 3rd arguments represent the difference list

  13. Non-terminals as structures • Translation into Prolog clausal form contd.: • pronoun(we) --> [we]. • pronoun(we, [we|L], L). • vp(vp(Y)) --> unergative(Y). • 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). • unergative(v(ran)) --> [ran]. • unergative(v(ran), [ran|L], L). • transitive(v(hit)) --> [hit]. • transitive(v(hit), [hit|L], L).

  14. Retrieving Parses • Prolog query • ?- s(X,[i,hit,the,ball],[]). • Note: • X precedes difference list • 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… • We can write a DCG for the context-sensitive language Labc = { anbncn | n >= 1 } (which cannot be encoded by any context-free grammar)

  16. DCG more powerful than Context-Free • Basic Idea: • Same trick for converting a+b+ into anbn • Modify non-terminals to pass around a counter • 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 • Let’s start by writing a grammar for anb+cn (which happens to be a context-free language)

  18. DCG more powerful than Context-Free • L(Gn+n) = { anb+cn | 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: • 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: • 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: • 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: • 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: • 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: • 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: • ?- 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

More Related