Notes on computational linguistics.pdf - UCLA Department of ...
Notes on computational linguistics.pdf - UCLA Department of ...
Notes on computational linguistics.pdf - UCLA Department of ...
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 />
/* earley.pl<br />
* E Stabler, Feb 2000<br />
* Earley parser, adapted from Shieber et al.<br />
* NB: the grammar must specify: startCategory(XXX).<br />
*/<br />
:- op(1200,xfx,: ˜ ). % this is our object language "if"<br />
:- [’closure-sics’]. % 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) :retractall(word(_,_)),<br />
% get rid <strong>of</strong> words from previous parse<br />
lexAxioms(0,Input,Axioms),<br />
closure(Axioms, Chart),<br />
nl, portray_clauses(Chart).<br />
computeClosure(Input,Chart) :retractall(word(_,_)),<br />
% get rid <strong>of</strong> words from previous parse<br />
lexAxioms(0,Input,Axioms),<br />
closure(Axioms, Chart).<br />
% for Earley, lexAxioms *asserts* word(i,WORDi) for each input word,<br />
% and then returns the single input axiom: item(start,[],[s],0,0)<br />
lexAxioms(_Pos,[],[item(start,[],[S],0,0)]) :startCategory(S).<br />
lexAxioms(Pos,[W|Ws],Axioms) :-<br />
Pos1 is Pos+1,<br />
assert(word(Pos1,W)),<br />
lexAxioms(Pos1,Ws,Axioms).<br />
inference( scan,<br />
[ item(A, Alpha, [W|Beta], I, J) ],<br />
% -----------------------------------item(A,<br />
[W|Alpha], Beta, I, J1),<br />
% where<br />
[J1 is J + 1,<br />
word(J1, W)] ).<br />
inference( predict,<br />
[ item(_A, _Alpha, [B|_Beta], _I,J) ],<br />
% --------------------------------------item(B,<br />
[], Gamma, J,J),<br />
% where<br />
[(B : ˜Gamma), eligible(Gamma,J)] ).<br />
inference( complete,<br />
[ item(A, Alpha, [B|Beta], I,J),<br />
item(B, _Gamma, [], J,K) ],<br />
% ------------------------------item(A,<br />
[B|Alpha], Beta, I,K),<br />
% where [] ).<br />
eligible([],_).<br />
eligible([A|_],_) :- \+ (\+ (A : ˜_)), !. % the double negati<strong>on</strong> leaves A unbound<br />
eligible([A|_],J) :- J1 is J+1, word(J1,A).<br />
portray_clauses([]).<br />
portray_clauses([C|Cs]) :- portray_clause(C), portray_clauses(Cs).<br />
114