1 / 15

LING 388: Language and Computers

LING 388: Language and Computers. Sandiway Fong 9/24 Lecture 9. Adminstrivia. Homework 2 graded class review today Homework 3 Recursion: s entential complements and relative clauses reminder: due Thursday. Homework 2 review. Question 1 : what does this do?

lynnea
Download Presentation

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 388: Language and Computers Sandiway Fong 9/24 Lecture 9

  2. Adminstrivia • Homework 2 • graded • class review today • Homework 3 • Recursion: • sentential complements and relative clauses • reminder: due Thursday

  3. Homework 2 review • Question 1: what does this do? • Query is: for what values of variables N and Argument is the Nth argument of Term true? • Answers: • N=1, Argument = nn(boy) • N=2, Argument = dt(the)

  4. Homework 2 review • Question 2: what does this do? • Query is: for what values of variables Arg1 and Arg2 is arg(2,Term,Arg1),arg(2,Arg1,Arg2) true? • Answer is: • Arg1 = pp(in(with),np(dt(a),nn(telescope))), • Arg2 = np(dt(a),nn(telescope)) In plain English: it picks out the 2nd sub-constituent of the 2nd sub-constituent of Term

  5. Homework 2 review • Question 3: give a Prolog query that picks out the word telescope from the compound term • Query is: Idea: take the 2nd argument of Term, that’s the PP constituent take the 2nd argument of PP, that’s the NP object of PP take the 2nd argument of NP, that’s the NN head of the NP Take the 1st argument of NN, that’s the word telescope

  6. Homework 2 review • Question 4: Given devise a query using =.. that produces the complex term NP: Answer is: arg1 arg2 Idea: Build term dt(the) using =.. applied to List1 Build term nn(telescope) using =.. applied to List2 Form the list [np,dt(the),nn(telescope)] Build term np(dt(the),nn(telescope)) using =..

  7. Homework 2 review • Question 5: devise a query using =.. that produces the complex term PP: • Answer is: Idea: Build term dt(the) using =.. applied to List1 Build term nn(telescope) using =.. applied to List2 Form the list [np,dt(the),nn(telescope)] Build term np(dt(the),nn(telescope)) using =.. Build term in(with) using =.. applied to List3 Form the list [pp,in(with), np(dt(the),nn(telescope))] Build term PP using =..

  8. Today’s Topic • Dealing with left recursion

  9. Right Recursive Rules • Example (right-recursive): • nn--> a, nn. • nn --> [bus]. • Example: big red shiny bus • Derivation (top-down, left-to-right): • nn • ann • bignn • big ann • big red nn • big red ann • big red shinynnand so on…

  10. Left Recursion • Given: • I saw the boy with a telescope (2 parses) • Strategy: • PP with a telescope adjoins to NP or VP: • np(np(NP,PP)) --> np(NP), pp(PP). • vp(vp(VP,PP)) --> vp(VP), pp(PP). Unfortunately, this is left recursive, and Prolog will crash..

  11. Left Recursion • Instead of: • np(np(DT,NN)) --> dt(DT), nn(NN). • np(np(NP,PP)) --> np(NP), pp(PP). • Quick fix: • np(np(DT,NN)) --> dt(DT), nn(NN). • np(np(DT,NN,PP)) --> dt(DT), nn(NN), pp(PP). • Can opt to return a left recursive parse: • np(np(DT,NN)) --> dt(DT), nn(NN). • np(np(np(DT,NN),PP))) --> dt(DT), nn(NN), pp(PP).

  12. Left Recursion • Instead of: • vp(vp(VBD,NP)) --> vbd(VBD), np(NP). • vp(vp(VP,PP)) --> vp(VP), pp(PP). • Quick fix: • vp(vp(VBD,NP)) --> vbd(VBD), np(NP). • vp(vp(VBD,NP,PP)) --> vbd(VBD), np(NP), pp(PP). • Can opt to return a left recursive parse: • vp(vp(VBD,NP)) --> vbd(VBD), np(NP). • vp(vp(vp(VBD,NP),PP)) --> vbd(VBD), np(NP), pp(PP).

  13. Another option Transform left recursive into right recursive rules Transformed example: x --> [z], v. v --> [y], v. v --> [y]. x --> [z]. Language: z zy zyy zyyy … Parses: [x z] x(z) [x z [v y]] x(z,v(y)) [x z [v y [v y]]] x(z,v(y,v(y))) [x z [v y [v y [v y]]]] x(z,v(y,v(y,v(y)))) • An abstract example: • x --> x, [y]. • x --> [z]. • Language generated by this grammar: • z • zy • zyy • zyyyand so on… • Parses: • [x z] x(z) • [x [x z] y] x(x(z),y) • [x [x [x z] y] y] x(x(x(z),y),y) • [x [x [x [x z] y] y] y] x(x(x(z),y),y),y) • and so on… rewrite as unchanged Same language!

  14. Another option • right recursive version: • x --> [z], v. • v --> [y], v. • v --> [y]. • x --> [z]. • add a parse: • x(x(z,V)) --> [z], v(V). • v(v(y,V)) --> [y], v(V). • v(v(v)) --> [y]. • x(x(z)) --> [z].

  15. Another option • We can still get a left recursive parse if we add a 2nd argument to nonterminal v: • Compare with: • x(x(z,V)) --> [z], v(V). • v(v(y,V)) --> [y], v(V). • v(v(v)) --> [y]. • x(x(z)) --> [z].

More Related