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

Problem (4), Soluti<strong>on</strong> 1:<br />

%File: badprog.pl<br />

% not so bad, really!<br />

% first, we load the first 2 columns <strong>of</strong> the Mitt<strong>on</strong> lexic<strong>on</strong><br />

:- [col12].<br />

test :- translate([’D’,’@’,k,’\&’,t,’I’,z,’O’,n,’D’,’@’,m,’\&’,t],Words), write(Words).<br />

%translate(Ph<strong>on</strong>es,Words)<br />

translate([],[]).<br />

translate(Ph<strong>on</strong>es,[Word|Words]) :append(FirstPh<strong>on</strong>es,RestPh<strong>on</strong>es,Ph<strong>on</strong>es),<br />

lex(Word,FirstPh<strong>on</strong>es),<br />

translate(RestPh<strong>on</strong>es,Words).<br />

We can test this program like this:<br />

1 ?- [badprog].<br />

% col12 compiled 2.13 sec, 52 bytes<br />

% badprog compiled 2.13 sec, 196 bytes<br />

Yes<br />

2 ?- translate([’D’,’@’,k,’&’,t,’I’,z,’0’, n,’D’,’@’,m,’&’,t],Words).<br />

Words = [the, cat, is, <strong>on</strong>, the, ’Matt’] ;<br />

Words = [the, cat, is, <strong>on</strong>, the, mat] ;<br />

Words = [the, cat, is, <strong>on</strong>, the, matt] ;<br />

No<br />

3 ?-<br />

Part b <strong>of</strong> the problem asks us to integrate this kind <strong>of</strong> translati<strong>on</strong> into the syntactic recognizer. Since we <strong>on</strong>ly<br />

want to do a dicti<strong>on</strong>ary lookup when we have a syntactic lexical item <strong>of</strong> the syntax, let’s represent the lexical<br />

items in the syntax with lists, like this:<br />

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

dp :˜ [d1]. d1 :˜ [d0, np]. d0 :˜ [[t,h,e]].<br />

np :˜ [n1]. n1 :˜ [n0]. n0 :˜ [[c,a,t]]. n0 :˜ [[m,a,t]].<br />

vp :˜ [v1]. v1 :˜ [v0,pp]. v0 :˜ [[i,s]].<br />

pp :˜ [p1]. p1 :˜ [p0,dp]. p0 :˜ [[o,n]].<br />

Now the syntactic atoms have a ph<strong>on</strong>etic structure, as a list <strong>of</strong> characters. We test this grammar in the following<br />

sessi<strong>on</strong> – notice each word is spelled out as a sequence <strong>of</strong> characters.<br />

2 ?- [badprog].<br />

% badprog compiled 0.00 sec, 2,760 bytes<br />

Yes<br />

3 ?- ([[t,h,e],[c,a,t],[i,s],[o,n],[t,h,e],[m,a,t]] ?˜ [ip]).<br />

34

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

Saved successfully!

Ooh no, something went wrong!