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

(11) We can implement this in SWI-prolog as follows:<br />

/*<br />

* file: recognize.pl<br />

*/<br />

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

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

[] ?˜ [].<br />

% metalanguage provability predicate<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 />

ip :˜ [dp, i1]. i1 :˜ [i0, vp]. i0 :˜ [will].<br />

dp :˜ [d1]. d1 :˜ [d0, np]. d0 :˜ [the].<br />

np :˜ [n1]. n1 :˜ [n0].<br />

n1 :˜ [n0, cp].<br />

n0 :˜ [idea].<br />

vp :˜ [v1]. v1 :˜ [v0]. v0 :˜ [suffice].<br />

cp :˜ [c1]. c1 :˜ [c0, ip]. c0 :˜ [that].<br />

(12) Then we can have a sessi<strong>on</strong> like this:<br />

2% swiprolog<br />

Welcome to SWI-Prolog (Versi<strong>on</strong> 3.2.9)<br />

Copyright (c) 1993-1999 University <strong>of</strong> Amsterdam. All rights reserved.<br />

For help, use ?- help(Topic). or ?- apropos(Word).<br />

1 ?- [recognize].<br />

recognize compiled, 0.01 sec, 3,128 bytes.<br />

Yes<br />

2 ?- [the,idea,will,suffice] ?˜ [ip].<br />

Yes<br />

3 ?- [idea,the,will] ?˜ [ip].<br />

No<br />

4 ?- [idea] ?˜ [Cat].<br />

Cat = np ;<br />

Cat = n1 ;<br />

Cat = n0 ;<br />

Cat = idea ;<br />

No<br />

5 ?- [will,suffice] ?˜ [Cat].<br />

Cat = i1 ;<br />

No<br />

6 ?- [will,suffice,will,suffice] ?˜ [C,D].<br />

C = i1<br />

D = i1 ;<br />

No<br />

7 ?- S ?˜ [ip].<br />

S = [the, idea, will, suffice] ;<br />

S = [the, idea, will, v0] ;<br />

S = [the, idea, will, v1]<br />

Yes<br />

29

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

Saved successfully!

Ooh no, something went wrong!