200 likes | 316 Views
LING 388: Language and Computers. Sandiway Fong Lecture 23 11/10. np. trace. Last Time. English wh -questions subject wh -questions: simple object wh -questions: complex wh -word fronting do -support tense goes with do DCG technology employed extra argument
E N D
LING 388: Language and Computers Sandiway Fong Lecture 23 11/10
np trace Last Time • English wh-questions • subject wh-questions: simple • object wh-questions: complex • wh-word fronting • do-support • tense goes with do • DCG technology employed • extra argument • nonterminal renaming sbar np s[objectwh] aux what np did vp [objectwh] v john buy
Grammar g22.pl s(S) vp(Z,Ending)
Exercise 1 • Modify the grammar to employ Wh-movement for both subject and object wh-questions • i.e. be able to generate the following structures: • [Sbar Who [S [NP trace] [VP bought [NP a book]]]] • [Sbar What did [S [NP John] [VP buy [NPtrace]]]] Exercise 1 Implemented last time
Exercise 1 • Given • [Sbar Who [S [NP trace] [VP bought [NP a book]]]] need grammar rules: • Sbarwh-NP S (with subject trace) • S (with subject trace) VP
Exercise 1 • Interrogatives are Sbar trees and declaratives are S trees. • Define parse/2 as follows: • Need to block wh-word in subject position to avoid generating the S trees for • Who bought a book?
Exercise 1 • Add call to checkQ/3 for declarative S grammar rule:
grammar components so far: English DCG Japanese DCG both are bi-directional can generate and parse with the same grammar advantage of using Prolog for that putting it all together into the same file... our first attempt at Machine Translation (MT) Exercise 2
Declarative Taroo-ga hon-o katta John a book bought ga = nominative case marker o = accusative case marker Wh-questions Taroo-ga nani-o katta ka nani: means what ka: sentence-final question particle dare-ga hon-o katta ka dare: means who DCG rules: s(s(Y,Z)) --> np(Y,Q1), nomcase, vp(Z,Q2), sf(Q1,Q2). vp(vp(Z,Y),Q) --> np(Z,Q), acccase, transitive(Y). transitive(v(katta)) --> [katta]. nomcase --> [ga]. acccase --> [o]. np(np(taroo),notwh) --> [taroo]. np(np(hon),notwh) --> [hon]. np(np(dare),wh) --> [dare]. np(np(nani),wh) --> [nani]. sf(wh,notwh) --> [ka]. sf(notwh,wh) --> [ka]. sf(notwh,notwh) --> []. sf(wh,wh) --> [ka]. Japanese: Data
Japanese: Grammar • DCG rules: • js(s(Y,Z)) --> jnp(Y,Q1), nomcase, jvp(Z,Q2), sf(Q1,Q2). • jvp(vp(Z,Y),Q) --> jnp(Z,Q), acccase, jtransitive(Y). • jtransitive(v(katta)) --> [katta]. • nomcase --> [ga]. • acccase --> [o]. • jnp(np(taroo),notwh) --> [taroo]. • jnp(np(hon),notwh) --> [hon]. • jnp(np(dare),wh) --> [dare]. • jnp(np(nani),wh) --> [nani]. • sf(wh,notwh) --> [ka]. • sf(notwh,wh) --> [ka]. • sf(notwh,notwh) --> []. • sf(wh,wh) --> [ka]. rename Japanese nonterminals to not clash with English grammar – we’re going to be loading them both at the same time
English: Data • Declarative: • John bought a book • Wh-Questions: • Who bought a book? (subject wh-phrase) • *John bought what? (only possible as an echo-question) • What did John buy? (object wh-phrase)
English: Grammar • We can also generate with this grammar • like with the Japanese grammar • Examples: • ?-s(s(np(john),vp(v(bought),np(det(a),n(book)))),Y,[]). • Y = [john,bought,a,book] • ?-sbar(sbar(np(what),aux(did),s(np(john),vp(v(buy)))),Y,[]). • Y = [what,did,john,buy] • ?-sbar(s(np(who),vp(v(bought),np(det(a),n(book)))),Y,[]). • Y = [who,bought,a,book]
Example 1 • declarative example • John bought a book • Taroo-ga hon-o katta • word correspondences • katta = bought • hon = book • Taroo John • ga = nominative case marker • o = accusative case marker • database facts • je(katta,bought). • je(hon,book). • je(taroo,john).
Example 1 • declarative example • John bought a book • Taroo-gahon-okatta • database facts • je(katta,bought). • je(hon,book). • je(taroo,john). • parse trees • ?-s(X,[john,bought,a,book],[]). • X = s(np(john),vp(v(bought),np(det(a),n(book)))) • ?-js(X,[taroo,ga,hon,o,katta],[]). • X = s(np(taroo),vp(np(hon),v(katta))) • translator (top-level): • ?-s(X,EnglishSentence,[]),maptree(X,Y),js(Y,JapaneseSentence,[]). • problem reduces to: • how to write predicate maptree/2 ?
Example 1 • declarative example • John bought a book s(np(john),vp(v(bought),np(det(a),n(book)))) • Taroo-gahon-okattas(np(taroo),vp(np(hon),v(katta))) • database facts (modified) • je(katta,bought).je(v(katta),v(bought)). • je(hon,book). je(np(hon),np(det(_),n(book))). • % no corresponding indefinite determiner in Japanese • je(taroo,john).je(np(taroo),np(john)). • predicate maptree/2 • idea: • map subject to subject, verb to verb, object to object, and • respect word-order differences in the trees • maptree(s(S,vp(V,O)),s(SJ,vp(OJ,VJ))) :- • je(SJ,S), • je(VJ,V), • je(OJ,O).
Example 1 • declarative example • John bought a book s(np(john),vp(v(bought),np(det(a),n(book)))) • Taroo-gahon-okattas(np(taroo),vp(np(hon),v(katta))) • predicate maptree/2
Example 1 • declarative example • John bought a book s(np(john),vp(v(bought),np(det(a),n(book)))) • Taroo-gahon-okattas(np(taroo),vp(np(hon),v(katta))) • query (EJ) • ?-translate([john,bought,a,book],J). • J = [taroo,ga,hon,o,katta] • query (JE) • ?-translate(E,[taroo,ga,hon,o,katta]). • E = [john,bought,the,book] (surprising!) • computation tree (JE) • ?-translate(E,[taroo,ga,hon,o,katta]). • ?- sbar(X,E,[]). • ?- maptree(X,Xp). • ?- js(Xp,[taroo,ga,hon,o,katta],[]). • What does the query ?- sbar(X,E,[]). do? • X represents the parse tree • E represents the input sentence • but both arguments are variables! • i.e. we’re not providing any information to the English grammar/parser