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

(14) With this parsing strategy, we can avoid all blind alleys in collecting a tree.<br />

/* ckypCollect.pl<br />

* E Stabler, Feb 2000<br />

* collect a tree from a CKY parser chart<br />

*/<br />

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

ckypCollect(Chart,N,S,S/STs) :- collectTree(Chart,0,S,N,S/STs).<br />

collectTree(Chart,I,A,J,A/ATs) :- member(((I,J):(A:˜L)),Chart), collectTrees(L,Chart,I,J,ATs).<br />

collectTree(Chart,I,W,J,W/[]) :- member(((I,J):(W:˜[])),Chart).<br />

collectTrees([],_,I,I,[]).<br />

collectTrees([A],Chart,I,J,[A/ATs]) :- collectTree(Chart,I,A,J,A/ATs).<br />

collectTrees([A,K|As],Chart,I,J,[A/ATs|Ts]) :- collectTree(Chart,I,A,K,A/ATs), collectTrees(As,Chart,K,J,Ts).<br />

(15) We have sessi<strong>on</strong>s like this:<br />

7 ?- [g1,ckypSWI,pp_tree].<br />

% g1 compiled 0.00 sec, 672 bytes<br />

% chart compiled 0.00 sec, 0 bytes<br />

% agenda compiled 0.00 sec, 0 bytes<br />

% items compiled 0.00 sec, 0 bytes<br />

% m<strong>on</strong>itor compiled 0.01 sec, 0 bytes<br />

% driver compiled 0.00 sec, 0 bytes<br />

% utilities compiled 0.00 sec, 0 bytes<br />

% closure-swi compiled 0.01 sec, 0 bytes<br />

% ckypSWI compiled 0.01 sec, 0 bytes<br />

% pp_tree compiled 0.00 sec, 1,692 bytes<br />

Yes<br />

8 ?- computeClosure([the,idea,will,suffice]).<br />

’.’’.’’.’’.’:’.’:’.’:’.’:’.’::’.’::’.’:’.’:’.’:’.’:’.’:’.’::’.’:<br />

(0, 1): (d0:˜[the]).<br />

(0, 1): (the:˜[]).<br />

(0, 2): (d1:˜[d0, 1, np]).<br />

(0, 2): (dp:˜[d1]).<br />

(0, 4): (ip:˜[dp, 2, i1]).<br />

(1, 2): (idea:˜[]).<br />

(1, 2): (n0:˜[idea]).<br />

(1, 2): (n1:˜[n0]).<br />

(1, 2): (np:˜[n1]).<br />

(2, 3): (i0:˜[will]).<br />

(2, 3): (will:˜[]).<br />

(2, 4): (i1:˜[i0, 3, vp]).<br />

(3, 4): (suffice:˜[]).<br />

(3, 4): (v0:˜[suffice]).<br />

(3, 4): (v1:˜[v0]).<br />

(3, 4): (vp:˜[v1]).<br />

Yes<br />

9 ?- [ckypCollect].<br />

% ckypCollect compiled 0.00 sec, 1,764 bytes<br />

Yes<br />

10 ?- computeClosure([the,idea,will,suffice],Chart),nl,ckypCollect(Chart,4,ip,T),pp_tree(T).<br />

’.’’.’’.’’.’:’.’:’.’:’.’:’.’::’.’::’.’:’.’:’.’:’.’:’.’:’.’::’.’:<br />

ip /[<br />

dp /[<br />

d1 /[<br />

d0 /[<br />

the /[]],<br />

np /[<br />

n1 /[<br />

n0 /[<br />

idea /[]]]]]],<br />

i1 /[<br />

i0 /[<br />

will /[]],<br />

vp /[<br />

v1 /[<br />

v0 /[<br />

suffice /[]]]]]]<br />

Chart = [ (0, 1): (d0:˜[the]), (0, 1): (the:˜[]), (0, 2): (d1:˜[d0, 1, np]), (0, 2): (dp:˜[d1]), (0, 4): (ip:˜[dp, 2|...]), (1, 2): (idea:˜[]), (1, 2): (n0:˜[...]), (...<br />

T = ip/[dp/[d1/[d0/[the/[]], np/[... /...]]], i1/[i0/[will/[]], vp/[v1/[...]]]]<br />

Yes<br />

11 ?-<br />

Exercise: What grammar is the intersecti<strong>on</strong> <strong>of</strong> g1.pl and the finite state language with just <strong>on</strong>e string,<br />

{the idea will suffice}.<br />

112

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

Saved successfully!

Ooh no, something went wrong!