CS105: Computer Programming: PYTHON Project 03 Assigned on Friday, October. 05, 2007 Due on Friday, October. 12 at 11:59PM ============= 1. Objectives ============= In this project, we implement a python script that computes frequency of each string in a given sentence. We will exclude some specific characters such as ",", ".", "!", "?", ";", "'", and '"' in a string. We assume that a sentence is already given in the script that you are implementing. Note that we will gradually add more functions in the next project. For example, (1) taking command-line arguments; (2) processing files; (2) implementing various sorting algorithms; and so on. ============== 2. Description ============== We will do the following requirements: (2.1) The script will be called "myWordCount.py" (2.2) The script (i.e., directory.py) will contain a string called "mySentence", which content is as follows: mySentence = """In this project, we implement a python script that computes frequency of each string in a given sentence. We will exclude some specific characters such as ",", ".", "!", "?", ";", "'", and '"' in a string. We assume that a sentence is already given in the script that you are implementing""" (2.3) It will contain the following functionalities: def printf(format, *args): def tokenizeString(mySentence): def cleanString(myWordList, myCharacter2Remove): def changeToLower(myWordList): def changeToUpper(myWordList): def removeCharacter(myWord, myCharacter2Remove): def countFrequency(myList): def getSortedKey(myDictionary): def printDictionary(myKeyList, myDictionary): def printByKeyLength(myKeyList, myDictionary, myLengthLimit): def printByFrequency(myKeyList, myDictionary, myFrequencyLimit): (2.4) Add "#!/usr/bin/env python" at the first line of your script so that the script can be run from the commandline as below: > ./myWordCount.py (2.5) From this project, all script should be well documented. ============================== 3. Grading criteria and policy ============================== Here are the details of each subroutine in the menu. NOTE: Your script will be graded based on how well the required functionality is fulfilled. Therefore, please follow the description as much as possible to get full credits. (3.01) def printf(format, *args):[==> 10 points] """implements Python version of printf() in C Language.""" (3.02) def tokenizeString(mySentence):[==> 10 points] """creates a list of words separated at whitespaces""" (3.03) def cleanString(myWordList, myCharacter2Remove):[==> 10 points] """removes (i.e., remove) all the characters (in a given list of characters to remove) from all words in a given word list. removeCharacter() will be called here.""" (3.04) def changeToLower(myWordList):[==> 10 points] """changes all words in a given word list into lower case characters.""" (3.05) def changeToUpper(myWordList):[==> 10 points] """changes all words in a given word list into upper case characters.""" (3.06) def removeCharacter(myWord, myCharacter2Remove):[==> 10 points] """removes the specified characters in each word.""" (3.07) def countFrequency(myList):[==> 10 points] """create a wordfrequency dictionary.""" (3.08) def getSortedKey(myDictionary):[==> 10 points] """creates a list of keys and sorts the list.""" (3.09) def printDictionary(myKeyList, myDictionary):[==> 10 points] """prints all pairs (i.e., key:value) in a given dictionary.""" (3.10) def printByKeyLength(myKeyList, myDictionary, myLengthLimit):[==> 10 points] """prints all pairs (i.e., key:value) in a given dictionary,""" whose key lengh >= the given length limit.""" (3.11) def printByFrequency(myKeyList, myDictionary, myFrequencyLimit):[==> 10 points] """prints all pairs (i.e., key:value) in a given dictionary,""" whose frequency >= the given frequency limit.""" ============================== 4. Grading criteria and policy ============================== Please make sure to include the followings at the header of the code. In summary, each script should contain AT LEAST the followings: -------------------------------------------------------------------- #!/usr/bin/env python # Project: 03 # Description: Count Word Frequency # Program: myWordCount.py # Input: NONE # Output: NONE # Usage: ./myWordCount.py # Name: Your name # UT EID: Your EID # Comments (or README): # Describe what you with to grader to know. # e.g., What did you like/dislike about this project? # What was the most challenging in this project? # etc. def printf(format, *args): """implements Python version of printf() in C Language.""" def tokenizeString(mySentence): """creates a list of words separated at whitespaces.""" def cleanString(myWordList, myCharacter2Remove): """removes (i.e., remove) all the characters (in a given list of characters to remove) from all words in a given word list. removeCharacter() will be called here.""" def changeToLower(myWordList): """changes all words in a given word list into lower case characters.""" def changeToUpper(myWordList): """changes all words in a given word list into upper case characters.""" def removeCharacter(myWord, myCharacter2Remove): """removes the specified characters in each word.""" def countFrequency(myList): """create a wordfrequency dictionary.""" def getSortedKey(myDictionary): """creates a list of keys and sorts the list.""" def printDictionary(myKeyList, myDictionary): """prints all pairs (i.e., key:value) in a given dictionary.""" def printByKeyLength(myKeyList, myDictionary, myLengthLimit): """prints all pairs (i.e., key:value) in a given dictionary,""" whose key lengh >= the given length limit.""" def printByFrequency(myKeyList, myDictionary, myFrequencyLimit): """prints all pairs (i.e., key:value) in a given dictionary,""" whose frequency >= the given frequency limit.""" if __name__ == '__main__': myCharacter2Remove = [",", ".", "!", "?", ";", "'", '"'] mySentence = """In this project, we implement a python script that computes frequency of each string in a given sentence. We will exclude some specific characters such as ",", ".", "!", "?", ";", "'", and '"' in a string. We assume that a sentence is already given in the script that you are implementing""" printf("\nSentence = ") printf("%s", mySentence) """CALL YOUR FUNCTIONS HERE""" printf("\n\n") ------------------------------------------------------------ ================== 5. Running example ================== The followings are expected upon running your script: -------------------------------------------------------------- > ./myWordCount.py # ./directoryModified.py Sentence = "In this project, we implement a python script that computes frequency of each string in a given sentence. We will exclude some specific characters such as ",", ".", "!", "?", ";", "'", and '"' in a string. We assume that a sentence is already given in the script that you are implementing" Frequency of each word in the sentence (sorted): { 'a':4, 'already':1, 'and':1, 'are':1, 'as':1, 'assume':1, 'characters':1, 'computes':1, 'each':1, 'exclude':1, 'frequency':1, 'given':2, 'implement':1, 'implementing':1, 'in':4, 'is':1, 'of':1, 'project':1, 'python':1, 'script':2, 'sentence':2, 'some':1, 'specific':1, 'string':2, 'such':1, 'that':3, 'the':1, 'this':1, 'we':3, 'will':1, 'you':1, } Frequency of each word (whose frequency >= 2) in the sentence (sorted): { 'a':4, 'given':2, 'in':4, 'script':2, 'sentence':2, 'string':2, 'that':3, 'we':3, } Frequency of each word (whose length >= 10) in the sentence (sorted): { 'characters':1, 'implementing':1, } Frequency of each word in the sentence (sorted): { 'A':4, 'ALREADY':1, 'AND':1, 'ARE':1, 'AS':1, 'ASSUME':1, 'CHARACTERS':1, 'COMPUTES':1, 'EACH':1, 'EXCLUDE':1, 'FREQUENCY':1, 'GIVEN':2, 'IMPLEMENT':1, 'IMPLEMENTING':1, 'IN':4, 'IS':1, 'OF':1, 'PROJECT':1, 'PYTHON':1, 'SCRIPT':2, 'SENTENCE':2, 'SOME':1, 'SPECIFIC':1, 'STRING':2, 'SUCH':1, 'THAT':3, 'THE':1, 'THIS':1, 'WE':3, 'WILL':1, 'YOU':1, } Frequency of each word (whose frequency >= 2) in the sentence (sorted): { 'A':4, 'GIVEN':2, 'IN':4, 'SCRIPT':2, 'SENTENCE':2, 'STRING':2, 'THAT':3, 'WE':3, } Frequency of each word (whose length >= 10) in the sentence (sorted): { 'CHARACTERS':1, 'IMPLEMENTING':1, } > ----------------------------------------------------------- ======= 6. NOTE ======= This project is worth a total of 120 (110 (functions) + 10 (style)) points. We'll discuss details about the project in the class. Submit one script file, "myWordCount.py", as follows: > turnin --submit hyukcho project03 myWordCount.py Good luck!