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

’[0]’([n|Rest]) :˜ [n,’[0n]’(Rest)].<br />

’[0n]’([]) :˜ [].<br />

’[m]’(Rest) :˜ [’&’,’[m&]’(Rest)].<br />

’[m&]’(Rest) :˜ [t,’[m&t]’(Rest)].<br />

’[m&t]’([m,a,t]) :˜ [].<br />

’[m&t]’([m,a,t,t]) :˜ [].<br />

’[m&t]’([’M’,a,t,t]) :˜ [].<br />

With can test this grammar this way:<br />

2 ?- [goodprog].<br />

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

Yes<br />

3 ?- ([’D’,’@’] ?˜ [lex(W)]).<br />

W = [t, h, e] ;<br />

No<br />

4 ?- ([m,’&’,t] ?˜ [lex(W)]).<br />

W = [m, a, t] ;<br />

W = [m, a, t, t] ;<br />

W = [’M’, a, t, t] ;<br />

No<br />

5 ?- ([m,’&’,t,’D’] ?˜ [lex(W)]).<br />

No<br />

6 ?-<br />

(It’s always a good idea to test your axioms with both positive and negative cases like this!)<br />

Now let’s extend this to part b <strong>of</strong> the problem. We can use the same syntax again, and simply modify the<br />

“scan” to notice when we are trying to find a syntactic atom – now represented by a list <strong>of</strong> characters – then<br />

we should try to parse it as a sequence <strong>of</strong> ph<strong>on</strong>es using our transducer.<br />

[] ?˜ [].<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([W|S],[W|C],S,C). % scan<br />

infer(Ph<strong>on</strong>es,[[Char|Chars]|C],Rest,C) :append([Ph<strong>on</strong>|Ph<strong>on</strong>s],Rest,Ph<strong>on</strong>es),<br />

([Ph<strong>on</strong>|Ph<strong>on</strong>s] ?˜ [lex([Char|Chars])]). % minor change here<br />

Now we can test the result.<br />

1 ?- [goodprog].<br />

% goodprog compiled 0.00 sec, 6,328 bytes<br />

Yes<br />

39

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

Saved successfully!

Ooh no, something went wrong!