20.07.2013 Views

Notes on computational linguistics.pdf - UCLA Department of ...

Notes on computational linguistics.pdf - UCLA Department of ...

Notes on computational linguistics.pdf - UCLA Department of ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Stabler - Lx 185/209 2003<br />

3.5 The top-down parser<br />

D<br />

the<br />

DP<br />

D’<br />

NP<br />

N’<br />

N<br />

penguin<br />

IP<br />

I’<br />

I VP<br />

V’<br />

V<br />

swims<br />

V’<br />

AdvP<br />

Adv’<br />

Adv<br />

beautifully<br />

(24) Any TD pro<strong>of</strong> can be represented as a tree, so let’s modify the TD provable ˜ predicate so that it not<br />

(25)<br />

<strong>on</strong>ly finds pro<strong>of</strong>s, but also builds tree representati<strong>on</strong>s <strong>of</strong> the pro<strong>of</strong>s that it finds.<br />

Recall that the TD ?˜ predicate is defined this way:<br />

/*<br />

* file: td.pl = ll.pl<br />

*<br />

*/<br />

:- op(1200,xfx,:˜). % this is our object language "if"<br />

:- op(1100,xfx,?˜). % provability predicate<br />

[] ?˜ [].<br />

(S0 ?˜ Goals0) :- infer(S0,Goals0,S,Goals), (S ?˜ Goals).<br />

infer(S,[A|C], S,DC) :- (A :˜ D), append(D,C,DC). % ll<br />

infer([A|S],[A|C], S,C). % scan<br />

append([],L,L).<br />

append([E|L],M,[E|N]) :- append(L,M,N).<br />

The predicate ?˜ takes 2 arguments: the list <strong>of</strong> lexical axioms (the “input string”) and the list <strong>of</strong> goals<br />

to be proven, respectively.<br />

In the sec<strong>on</strong>d rule, when subgoal A expands to subgoals D, we want to build a tree that shows a node<br />

labeled A dominating these subgoals.<br />

(26) The parser is trickier; going through it carefully will be left as an opti<strong>on</strong>al exercise. We add a third<br />

argument in which to hold the pro<strong>of</strong> trees.<br />

/*<br />

* file: tdp.pl = llp.pl<br />

*/<br />

:- op(1200,xfx,:˜). % this is our object language "if"<br />

:- op(1100,xfx,?˜). % provability predicate<br />

:- op(500,yfx,@). % metalanguage functor to separate goals from trees<br />

[] ?˜ []@[].<br />

(S0 ?˜ Goals0@T0) :- infer(S0,Goals0@T0,S,Goals@T), (S ?˜ Goals@T).<br />

infer(S,[A|C]@[A/DTs|CTs],S,DC@DCTs) :- (A :˜ D), new_goals(D,C,CTs,DC,DCTs,DTs). \% ll<br />

infer([A|S],[A|C]@[A/[]|CTs],S,C@CTs). \% scan<br />

%new_goals(NewGoals,OldGoals,OldTrees,AllGoals,AllTrees,NewTrees)<br />

new_goals([],Gs,Ts,Gs,Ts,[]).<br />

new_goals([G|Gs0],Gs1,Ts1,[G|Gs2],[T|Ts2],[T|Ts]) :- new_goals(Gs0,Gs1,Ts1,Gs2,Ts2,Ts).<br />

In this code new_goals really does three related things at <strong>on</strong>ce. In the sec<strong>on</strong>d clause <strong>of</strong> ?˜, for example,<br />

the call to new_goals<br />

i. appends goals D and C to obtain the new goal sequence DC;<br />

ii. for each element <strong>of</strong> D, it adds a tree T to the list CTs <strong>of</strong> trees, yielding DCTs; and<br />

iii. each added tree T is also put into the list <strong>of</strong> trees DTs corresp<strong>on</strong>ding to D.<br />

47

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!