|
8 | 8 | "\n",
|
9 | 9 | "## Due: Friday the 27th of September 2019 23:59 p.m.\n",
|
10 | 10 | "\n",
|
11 |
| - "* Please submit your assignment (notebooks of parts 3a and 3b + Python modules) as **a single .zip file** using [this google form](https://forms.gle/JiDmuLLKxbjgA8Sn8)\n", |
| 11 | + "* Please submit your assignment (notebooks of parts 3a and 3b + Python modules) as **a single .zip file** using [this google form](https://forms.gle/JiDmuLLKxbjgA8Sn8). Please put the notebooks for Assignment 3a and 3b as well as the Python modules (files ending with .py) in one folder, which you call ASSIGNMENT_3_FIRSTNAME_LASTNAME. Please zip this folder and upload it as your submission.\n", |
12 | 12 | "\n",
|
13 | 13 | "* Please name your zip file with the following naming convention: ASSIGNMENT_3_FIRSTNAME_LASTNAME.zip\n",
|
14 | 14 | "\n",
|
|
23 | 23 | "* Chapter 15 - Off to analyzing text \n",
|
24 | 24 | "\n",
|
25 | 25 | "\n",
|
26 |
| - "In this assignment, you will first complete a number of small exercises about each chapter to make sure you are familiar with the most important concepts. In the second part of the assignment, you will apply your newly acquired skills to write your very own text processing program (ASSIGNMENT-3b) :-). But don't worry, there will be instructions and hints along the way. " |
| 26 | + "In this assignment, you will first complete a number of small exercises about each chapter to make sure you are familiar with the most important concepts. In the second part of the assignment, you will apply your newly acquired skills to write your very own text processing program (ASSIGNMENT-3b) :-). But don't worry, there will be instructions and hints along the way. \n", |
| 27 | + "\n", |
| 28 | + "**Can I use external modules?**\n", |
| 29 | + "For now, please try to avoid it. All the exercises can be solved with what we have covered in block I, II, and III\n", |
| 30 | + "\n", |
| 31 | + "\n", |
| 32 | + "\n" |
27 | 33 | ]
|
28 | 34 | },
|
29 | 35 | {
|
|
47 | 53 | "\n",
|
48 | 54 | "* Hint 1: There is a specific python container which does not allow for duplicates and simply removes them. Use this one. \n",
|
49 | 55 | "* Hint 2: There is a function which sorts items in an iterable called 'sorted'. Look at the documentation to see how it is used. \n",
|
50 |
| - "* Hint 3: Don't forget to write a docstring. " |
| 56 | + "* Hint 3: Don't forget to write a docstring. Please make sure that the docstring generally explains with the input is, what the function does, and what the function returns. If you want, but this is not needed to receive full points, you can use [reStructuredText](http://docutils.sourceforge.net/rst.html)." |
51 | 57 | ]
|
52 | 58 | },
|
53 | 59 | {
|
|
73 | 79 | "metadata": {},
|
74 | 80 | "source": [
|
75 | 81 | "### Exercise 2\n",
|
76 |
| - "NLTK offers a way of using WordNet in Python. Do some research (using google, because quite frankly, that's what we do very often) and see if you can find out how to import it. WordNet is a computational lexicon which organizes words according to their senses (collected in synsets). See if you can print all the synset definitions (i.e. entries) of the word 'dog'.\n", |
| 82 | + "NLTK offers a way of using WordNet in Python. Do some research (using google, because quite frankly, that's what we do very often) and see if you can find out how to import it. WordNet is a computational lexicon which organizes words according to their senses (collected in synsets). See if you can print all the **synset definitions** of the lemma **dog**.\n", |
77 | 83 | "\n",
|
78 | 84 | "Make sure you have run the following cell to make sure you have installed WordNet:"
|
79 | 85 | ]
|
|
114 | 120 | "### Exercise 3\n",
|
115 | 121 | "\n",
|
116 | 122 | "\n",
|
117 |
| - "#### a.) Define a function called `count` which counts the words in a string. Do not use NLTK just yet. Find a way to test it. \n", |
118 |
| - "* Hint 1: Write a helper-function called `preprocess` which preprocesses the string (split it, remove the punctuation specified by the user, return it in a container that you think works best for the next steps). You call the function `preprocess` inside the `count` function.\n", |
| 123 | + "#### a.) Define a function called `count` which determine how often each word occurs in a string. Do not use NLTK just yet. Find a way to test it. \n", |
| 124 | + "* Hint 1: Write a helper-function called `preprocess` which preprocesses the string (remove the punctuation specified by the user, split it, return it in a container that you think works best for the next steps). You call the function `preprocess` inside the `count` function.\n", |
119 | 125 | "\n",
|
120 | 126 | "* Hint 2: Remember that there are string methods which you can use to get rid of unwanted characters. Test the `preprocess` function using the string 'this is a (tricky) test'. No assert statements are needed.\n",
|
121 | 127 | "\n",
|
|
125 | 131 | "\n",
|
126 | 132 | "#### b.) Create a python script \n",
|
127 | 133 | "\n",
|
128 |
| - "Use your editor to create a python script called `count_words.py`. Move your function call of the **count** function to this file. Move your helper function (**preprocess**) to a seperate script which you call `utils_3a.py`. Import your helper function into `count_words.py`. Test whether everything works as expected by calling the scipt `count_words.py` from the terminal. \n", |
| 134 | + "Use your editor to create a Python script called **count_words.py**. You place the function definition of the **count** function in **count_words.py**. You also place a function call of the **count** function in this file to test it. Place your helper function definition, i.e., **preprocess**, in a separate script called **utils_3a.py**. Import your helper function **preprocess** into count_words.py. Test whether everything works as expected by calling the script count_words.py from the terminal.\n", |
| 135 | + "\n", |
| 136 | + "The function **preprocess** preprocesses the text by removing characters that are unwanted by the user. The function **count** builds upon the output from the preprocess function and creates a dictionary in which the key is a word and the value is the frequency of the word.\n", |
129 | 137 | "\n",
|
130 | 138 | "**Please submit these scripts together with the other notebooks**.\n",
|
131 | 139 | "\n",
|
|
162 | 170 | "a.) Write a function called `load_text` which opens and reads a file and returns the text in the file. It should take a filepath as a argument. Test it by loading this file: ../Data/lyrics/walrus.txt\n",
|
163 | 171 | "\n",
|
164 | 172 | "* Hint: remember it is best practice to use a context manager\n",
|
| 173 | + "* Hint: **FileNotFoundError**: This means that the path you provide does not lead to an existing file on your computer. Please carefully study Chapter 14. Please determine where the notebook or Python module that you are working with is located on your computer. Try to determine where Python is looking if you provide a path such as “../Data/lyrics/walrus.txt”. Try to go from your notebook to the location on your computer where Python is trying to find the file. One tip: if you did not store the Assignments notebooks 3a and 3b in the folder “Assignments”, you will get this error.\n", |
165 | 174 | "\n",
|
166 | 175 | "b.) Write a function called `replace_walrus` which takes lyrics as input and replaces every instance of 'walrus' by 'hippo' (make sure to account for upper and lower case - it is fine to transform everything to lower case). The function should write the new version of the song to a file called 'walrus_hippo.txt and stored in ../Data/lyrics. \n",
|
167 | 176 | "\n",
|
|
257 | 266 | "[answer]"
|
258 | 267 | ]
|
259 | 268 | },
|
260 |
| - { |
261 |
| - "cell_type": "code", |
262 |
| - "execution_count": null, |
263 |
| - "metadata": { |
264 |
| - "collapsed": true |
265 |
| - }, |
266 |
| - "outputs": [], |
267 |
| - "source": [ |
268 |
| - "# your code here" |
269 |
| - ] |
270 |
| - }, |
271 | 269 | {
|
272 | 270 | "cell_type": "markdown",
|
273 | 271 | "metadata": {},
|
|
281 | 279 | "source": [
|
282 | 280 | "[answer]"
|
283 | 281 | ]
|
284 |
| - }, |
285 |
| - { |
286 |
| - "cell_type": "markdown", |
287 |
| - "metadata": {}, |
288 |
| - "source": [] |
289 | 282 | }
|
290 | 283 | ],
|
291 | 284 | "metadata": {
|
|
304 | 297 | "name": "python",
|
305 | 298 | "nbconvert_exporter": "python",
|
306 | 299 | "pygments_lexer": "ipython3",
|
307 |
| - "version": "3.7.2" |
| 300 | + "version": "3.6.8" |
308 | 301 | }
|
309 | 302 | },
|
310 | 303 | "nbformat": 4,
|
|
0 commit comments