5.9 Assignment 9Due date: Friday, March 22, 2019 at 11:55 pm.
Be sure to use version control Problem
a) Create a file "myutils.py" which contains a function called 'word_count', that accepts two string arguments, one mandatory and one optional. The function should decompose the mandatory first string argument into its component words, create a dictionary which contains a key for each word, and assign each key's value the number of times that word appears in the string.
Note the string function "split" will be useful here. Also, the dictionary function 'setdefault' is also useful. b) Add another function named "read_file" to the file "myutils.py". This function should receive a file name as an argument, read the file and return its contents. You can use the first three commands in this sequence of commands as an outline of how to read the data from the file.
c) Download the file plotTopWords.py (link: https://support.scinet.utoronto.ca/~alexey/plotTopWords.py) and add it to your git repository.
d) Create a Python driver script called "count_words.py" and import your file "myutils.py". You should not hard code the file names in your script. Use command line arguments to pass the file name into the script.
e) Download the file stopwords_en.txt (link: https://support.scinet.utoronto.ca/~alexey/stopwords_en.txt) containing several stop words. Modify your driver script so that it will now take an optional argument. This optional second argument is a file of stop words. If the optional stop-words-file argument is supplied, the script should run the function "myutils.word_count" using the stop words taken from the stop words file. f) Create a bash script named "compare_words.sh" that runs your script "count_words.py" twice:
Submit your
To capture the output of Assignments will be graded on a 10 point basis. Due date is March 22, 2019 at 11:55pm, with 0.5 point penalty per day for late submission until the cut-off date of March 29, 2019 at 11:00am.
Last Modified: Friday Mar 15, 2019 - 11:33. Revision: 54. Release Date: Friday Mar 15, 2019 - 10:00.
|
|
Questions? Contact Support.
Web site engine's code is copyright © ATutor®. Modifications and code of added modules are copyright of SciNet. |