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

7.2.2 Collecting trees: a better perspective<br />

(12) We can make tree collecti<strong>on</strong> easier by putting additi<strong>on</strong>al informati<strong>on</strong> into the chart, so that the chart<br />

can be regarded as a “packed forest” <strong>of</strong> subtrees from which any successful derivati<strong>on</strong>s can easily be<br />

extracted. We call the forest “packed” because a single item in the chart can participate in many (even<br />

infinitely many) trees.<br />

One versi<strong>on</strong> <strong>of</strong> this idea was proposed by Tomita (1985), and Billot and Lang (1989) noticed the basic idea<br />

menti<strong>on</strong>ed in the introducti<strong>on</strong>: that what we want is a certain way <strong>of</strong> computing the intersecti<strong>on</strong> between<br />

a regular language (represented by a finite state machine) and a c<strong>on</strong>text free language (represented by<br />

ac<strong>on</strong>textfreegrammar).<br />

(13) We can implement this idea as follows: in each item, we indicate which rule was used to create it, and<br />

we also indicate the “internal” positi<strong>on</strong>s:<br />

/* ckypSWI.pl<br />

* E Stabler, Feb 2000<br />

* CKY parser, augmented with rules for 0,3,4,5,6-tuples<br />

*/<br />

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

:- [’closure-swi’]. % defines closure/2, uses inference/4<br />

%verbose. % comment to reduce verbosity <strong>of</strong> chart c<strong>on</strong>structi<strong>on</strong><br />

computeClosure(Input) :lexAxioms(0,Input,Axioms),<br />

closure(Axioms, Chart),<br />

nl, portray_clauses(Chart).<br />

computeClosure(Input,Chart) :lexAxioms(0,Input,Axioms),<br />

closure(Axioms, Chart).<br />

lexAxioms(_Pos,[],L) :bag<strong>of</strong>0(((X,X):(A:˜[])),(A<br />

:˜ []),L).<br />

lexAxioms(Pos,[W|Ws],[((Pos,Pos1):(W:˜[]))|Axioms]) :-<br />

Pos1 is Pos+1,<br />

lexAxioms(Pos1,Ws,Axioms).<br />

inference(reduce1,<br />

[ (Pos,Pos1):(W:˜_) ],<br />

((Pos,Pos1):(A:˜[W])),<br />

[(A :˜ [W])] ).<br />

inference(reduce2,<br />

[ ((Pos,Pos1):(B:˜_)), ((Pos1,Pos2):(C:˜_))],<br />

((Pos,Pos2):(A:˜[B,Pos1,C])),<br />

[(A :˜ [B,C])] ).<br />

inference(reduce3,<br />

[ ((Pos,Pos1):(B:˜_)), ((Pos1,Pos2):(C:˜_)), ((Pos2,Pos3):(D:˜_))],<br />

(Pos,(A:˜[B,Pos1,C,Pos2,D]),Pos3),<br />

[(A :˜ [B,C,D])] ).<br />

inference(reduce4,<br />

[ ((Pos,Pos1):(B:˜_)), ((Pos1,Pos2):(C:˜_)), ((Pos2,Pos3):(D:˜_)), ((Pos3,Pos4):(E:˜_))],<br />

((Pos,Pos4):(A:˜[B,Pos1,C,Pos2,D,Pos3,E])),<br />

[(A :˜ [B,C,D,E])] ).<br />

inference(reduce5,<br />

[ ((Pos,Pos1):(B:˜_)), ((Pos1,Pos2):(C:˜_)), ((Pos2,Pos3):(D:˜_)), ((Pos3,Pos4):(E:˜_)), ((Pos4,Pos5):(F:˜_))],<br />

((Pos,Pos5):(A:˜[B,Pos1,C,Pos2,D,Pos3,E,Pos4,F])),<br />

[(A :˜ [B,C,D,E,F])] ).<br />

inference(reduce6,<br />

[ ((Pos,Pos1):(B:˜_)), ((Pos1,Pos2):(C:˜_)), ((Pos2,Pos3):(D:˜_)), ((Pos3,Pos4):(E:˜_)), ((Pos4,Pos5):(F:˜_)), ((Pos5,Pos6):(F:˜_))],<br />

((Pos,Pos6):(A:˜[B,Pos1,C,Pos2,D,Pos3,E,Pos4,F,Pos5,G])),<br />

[(A :˜ [B,C,D,E,F,G])] ).<br />

portray_clauses([]).<br />

portray_clauses([C|Cs]) :- portray_clause(C), portray_clauses(Cs).<br />

bag<strong>of</strong>0(A,B,C) :- bag<strong>of</strong>(A,B,C), !.<br />

bag<strong>of</strong>0(_,_,[]).<br />

111

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

Saved successfully!

Ooh no, something went wrong!