Yliopiston etusivulle In English
Helsingin yliopisto
clt231: Introduction to Natural Language Processing - lukuvuosi 2009-2010

Yhteystiedot

Nykykielten laitos

PL 24 (Unioninkatu 40)
00014 HELSINGIN YLIOPISTO

Puhelin +358 (09) 1911 (vaihde)
Faksi +358 (09) 191 28313

9. Processing Raw Text.

  • Lecture notes
  • Further reading
  • Practical work
    • In honour of Michael Palin, define a function isPalin(string) that decides whether string is a palindrome. This is a Boolean function, it returns True if string is a palindrome or False if it is not.
    • Write code to test the function with strings like "spam maps", "Palin Drome". The tests should output the results, like this:
      "spam maps" is a palindrome.
      "Palin Drome" is not a palindrome.
    • Note that the test result messages are output by the test code, not by the function. The function only returns True or False.
    • Define a non-Boolean function normalize(string) that takes a string argument and returns a new string with all punctuation and whitespace removed and all uppercase letters changed to lowercase letters.
    • Test this function with strings like "Spam! Maps!", "Palin? Drome?". The tests should output messages, like this:
      "Spam! Maps!" normalized to "spammaps".
      "Palin? Drome?" normalized to "palindrome".
    • Define a Boolean function isPalinNormal(string) that decides whether string is a palindrome, disregarding upper/lowercase, punctuation and whitespace. Use both normalize() and isPalin() inside isPalinNormal().
    • Test this function with strings like "Spam! Maps!", "Palin? Drome?". The tests should output messages, like this:
      "Spam! Maps!" is a palindrome when normalized.
      "Palin? Drome?" is not a palindrome when normalized.

Assignment 3.

© 2006-2009 Graham Wilcock

Hae laitoksen sivuilta:

Laitoksen etusivulle | Tiedekunnan etusivulle | Yliopiston etusivulle

Copyright © 2003-2005 Helsingin yliopisto. Kaikki oikeudet pidätetään.