- 71 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about ' LING 388: Language and Computers' - lynnea

**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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Adminstrivia

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

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)

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

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

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 =..

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 =..

Today’s Topic

- Dealing with left recursion

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…

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..

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).

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).

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!

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].

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].

Download Presentation

Connecting to Server..