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

3 more exercises with sequences – easy, medium, challenging!<br />

(4) Define a predicate countOccurrences(E,L,Count) that will take a list L, an element E, and return the Count<br />

<strong>of</strong> the number <strong>of</strong> times E occurs in L, in decimal notati<strong>on</strong>.<br />

Test your predicate by making sure you get the right resp<strong>on</strong>se to these tests:<br />

?- countOccurrences(s,[m,i,s,s,i,s,s,i,p,p,i],N).<br />

N = 4 ;<br />

No<br />

?- countOccurrences(x,[m,i,s,s,i,s,s,i,p,p,i],N).<br />

N = 0 ;<br />

No<br />

(5) Define a predicate reduplicated(L) that will be provable just in case list L can be divided in half – i.e. into<br />

two lists <strong>of</strong> the same length – where the first and sec<strong>on</strong>d halves are the same.<br />

Test your predicate by making sure you get the right resp<strong>on</strong>se to these tests:<br />

?- reduplicated([w,u,l,o]).<br />

No<br />

?- reduplicated([w,u,l,o,w,u,l,o]).<br />

Yes<br />

This might remind you <strong>of</strong> “reduplicati<strong>on</strong>” in human languages. For example, in Bambara, an African<br />

language spoken by about 3 milli<strong>on</strong> people in Mali and nearby countries, we find an especially simple<br />

kind <strong>of</strong> “reduplicati<strong>on</strong>” structure, which we see in complex words like this:<br />

wulu ‘dog’ wulo o wulo ‘whichever dog’<br />

malo ‘rice’ malo o malo ‘whichever rice’<br />

*malo o wulu NEVER!<br />

mal<strong>on</strong>yinina ‘some<strong>on</strong>e who looks for rice’ mal<strong>on</strong>yinina o mal<strong>on</strong>yinina ‘whoever looks for rice’<br />

(6) Define a predicate palindrome(L) that will be provable just in case when you look at the characters in<br />

the atoms <strong>of</strong> list L, L is equal to its reverse.<br />

Test your predicate by making sure you get the right resp<strong>on</strong>se to these tests:<br />

?- palindrome([wuloowulo]).<br />

No<br />

?- palindrome([hannah]).<br />

Yes<br />

?- palindrome([mary]).<br />

No<br />

?- palindrome([a,man,a,plan,a,canal,panama]).<br />

Yes<br />

24

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

Saved successfully!

Ooh no, something went wrong!