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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Stabler - Lx 185/209 2003<br />

7.1.2 CKY extended<br />

(5) We can relax the requirement that the grammar be in Chomsky normal form. For example, to allow<br />

arbitrary empty producti<strong>on</strong>s, and rules with right sides <strong>of</strong> length 3,4,5,6, we could add the following<br />

rules:<br />

(i, i) : A<br />

(i, j) : B (j,k) : C (k,l) : D<br />

(i, l) : A<br />

(i, j) : B (j,k) : C (k,l) : D (l,m) : E<br />

(i, m) : A<br />

(i, j) : B (j,k) : C (k,l) : D (l,m) : E (m,n) : F<br />

(i, n) : A<br />

(i, j) : B (j,k) : C (k,l) : D (l,m) : E (m,n) : F (n,o) : G<br />

(i, o) : A<br />

[reduce0] if A → ɛ<br />

[reduce3] if A → BCD<br />

[reduce4] if A → BCDE<br />

[reduce5] if A → BCDEF<br />

[reduce6] if A → BCDEFG<br />

(6) While this augmented parsing method is correct, it pays a price in efficiency. The Earley method <strong>of</strong> the<br />

next secti<strong>on</strong> can do better.<br />

(7) Using the strategy <strong>of</strong> computing closures (introduced in (39) <strong>on</strong> page 91), we can implement the CKY<br />

method with these extensi<strong>on</strong>s easily:<br />

/* ckySWI.pl<br />

* E Stabler, Feb 2000<br />

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

*/<br />

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

:- [’closure-swi’]. % Shieber et al’s definiti<strong>on</strong> <strong>of</strong> 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) :computeClosure(Input,Chart),<br />

nl,portray_clauses(Chart).<br />

/* ES tricky way to get the axioms from reduce0: */<br />

/* add them all right at the start */<br />

/* (there are more straightforward ways to do it but they are slower) */<br />

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

findall((Pos,Pos):A,(A :˜ []),Empties),<br />

append(Axioms0,Empties,Axioms),<br />

closure(Axioms, Chart).<br />

lexAxioms(_Pos,[],[]).<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,<br />

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

inference(reduce2,<br />

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

(Pos,Pos2):A,<br />

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

/* reduce0 is here! */<br />

/* for efficiency, comment out the rules you never use */<br />

inference(reduce3,<br />

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

(Pos,Pos3):A,<br />

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

inference(reduce4,<br />

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

(Pos,A,Pos4),<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,<br />

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

105

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

Saved successfully!

Ooh no, something went wrong!