CIT 590 Assignment 2: Pig Latin
Fall 2015, David Matuszek

Purposes of this assignment

General idea of the assignment

In this assignment you will write a program to translate English sentences into "Pig Latin."

Pig Latin is a "secret" language used by children, often in the belief that their parents won't understand them. The rules are simple:

The innocent-sounding words "vowel" and "word" are not easy to define precisely. For the purposes of this assignment:

Details

Write the following functions and the tests for them. In fact, I strongly recommend that you write the tests first. To do this, you can begin with a stub function--one that exists so that you can call it, but that doesn't actually do anything. For example:
def piggify_word(word):
  return word
Now write the test. It should fail (if it doesn't, already there's something wrong). Then write the code, test it, and debug until it works. Once it's working, refactor it--clean up any little things that could be done better--and make sure it still works.

If you find, later on, that you need to add to the code to cover cases that you missed, begin by writing tests for those cases.

Please name your files pig_latin.py and pig_latin_test.py.

Functions

You will probably find it easiest to test and write the following functions in the order given, as later functions depend on earlier ones.
def is_vowel(ch)
Return True if ch is a vowel, False if it isn't.
def cut(word)
Given a word (as defined above), return a 2-tuple. The first element of the tuple is the string of consonants at the beginning of the word (could be the empty string), and the second element is a string of all the remaining characters. For example, cut("String") should return the tuple ("Str", "ing").
def piggify_word(word)
Returns the Pig Latin version of a single word. (Hint: Use the cut function.)
def clean_word(raw_word)
"Cleans" the given "raw" word by removing any non-letter characters from the end, and returning a 2-tuple of the cleaned word and the removed characters. For example, clean_word("Wow!") should return ("Wow", "!").
def get_raw_words(sentence)
Uses the space character (' ') to separate the sentence into a list of word-like chunks ("raw" words), and returns that list of chunks. For example, get_raw_words("Madam, I'm Adam.") should return the list ["Madam,", "I'm", "Adam."].
def piggify_pairs(pair_list)
Takes a list of (word, punctuation) pairs and returns the corresponding list of ("piggified" word, punctuation) pairs. For example, piggify_pairs([("hi", ""), ("there", "!")]) should return [("ihay", ""), ("erethay", "!")].
def reassemble(pair_list)
Reassembles a list of (word, punctuation) pairs into a sentence. The word and its associated punctuation are concatenated, and the words are assembled into a sentence, with spaces between words (but no space at the beginning or at the end). For example, reassemble([("ihay", ""), ("erethay", "!")]) should return "ihay erethay!".
def piggify_sentence(sentence)
Takes a sentence, turns each word in the sentence into the corresponding Pig Latin version, then returns the altered sentence. Punctuation is preserved.
def main()
Ask the user to type in sentences. For each line that is read in, the function prints out the corresponding Pig Latin version. Quits the program (by reaching the end of the main method) when the user enters a blank line. This is the only function that does input/output, and is the only function that does not require a unit test.

Coda

At the end of your Python program (after all your function definitions), insert the following lines:

if __name__ == "__main__":
  main()
Here's what this does. If you are in the IDLE window containing your program, and you click F5 (or choose Run -> Run module) from the menu, IDLE will automatically run your main function. If you are in the IDLE window containing your test cases (supplied) and click F5 or use the menu equivalent, it will run the tests and tell you the results.

When you make a change in your program, be sure to save it before running your tests.

Due date

Zip your two Python files and turn them in to Canvas by 6am Wednesday, September 9.