Skip to content

Commit f280b89

Browse files
committed
updated Assignment 3 with FAQs
1 parent 60693be commit f280b89

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

Assignments/ASSIGNMENT-3a.ipynb

+17-24
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"\n",
99
"## Due: Friday the 27th of September 2019 23:59 p.m.\n",
1010
"\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",
1212
"\n",
1313
"* Please name your zip file with the following naming convention: ASSIGNMENT_3_FIRSTNAME_LASTNAME.zip\n",
1414
"\n",
@@ -23,7 +23,13 @@
2323
"* Chapter 15 - Off to analyzing text \n",
2424
"\n",
2525
"\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"
2733
]
2834
},
2935
{
@@ -47,7 +53,7 @@
4753
"\n",
4854
"* Hint 1: There is a specific python container which does not allow for duplicates and simply removes them. Use this one. \n",
4955
"* 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)."
5157
]
5258
},
5359
{
@@ -73,7 +79,7 @@
7379
"metadata": {},
7480
"source": [
7581
"### 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",
7783
"\n",
7884
"Make sure you have run the following cell to make sure you have installed WordNet:"
7985
]
@@ -114,8 +120,8 @@
114120
"### Exercise 3\n",
115121
"\n",
116122
"\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",
119125
"\n",
120126
"* 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",
121127
"\n",
@@ -125,7 +131,9 @@
125131
"\n",
126132
"#### b.) Create a python script \n",
127133
"\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",
129137
"\n",
130138
"**Please submit these scripts together with the other notebooks**.\n",
131139
"\n",
@@ -162,6 +170,7 @@
162170
"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",
163171
"\n",
164172
"* 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",
165174
"\n",
166175
"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",
167176
"\n",
@@ -257,17 +266,6 @@
257266
"[answer]"
258267
]
259268
},
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-
},
271269
{
272270
"cell_type": "markdown",
273271
"metadata": {},
@@ -281,11 +279,6 @@
281279
"source": [
282280
"[answer]"
283281
]
284-
},
285-
{
286-
"cell_type": "markdown",
287-
"metadata": {},
288-
"source": []
289282
}
290283
],
291284
"metadata": {
@@ -304,7 +297,7 @@
304297
"name": "python",
305298
"nbconvert_exporter": "python",
306299
"pygments_lexer": "ipython3",
307-
"version": "3.7.2"
300+
"version": "3.6.8"
308301
}
309302
},
310303
"nbformat": 4,

Assignments/ASSIGNMENT-3b.ipynb

+21-3
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,26 @@
8383
" \n",
8484
"for name, url in book_urls.items():\n",
8585
" text = download_book(url)\n",
86-
" with open('../Data/books/'+name+'.txt', 'w') as outfile:\n",
86+
" with open('../Data/books/'+name+'.txt', 'w', encoding='utf-8') as outfile:\n",
8787
" outfile.write(text)"
8888
]
8989
},
90+
{
91+
"cell_type": "markdown",
92+
"metadata": {},
93+
"source": [
94+
"**Encoding issues with txt files**\n",
95+
"\n",
96+
"For Windows users, the file “AnnaKarenina.txt” gets the encoding cp1252. \n",
97+
"In order to open the file, you have to add **encoding='utf-8'**, i.e.,\n",
98+
"\n",
99+
"```python\n",
100+
"a_path = 'some path on your computer.txt'\n",
101+
"with open(a_path, mode='r', encoding='utf-8'):\n",
102+
" # process file\n",
103+
"```"
104+
]
105+
},
90106
{
91107
"cell_type": "markdown",
92108
"metadata": {},
@@ -198,6 +214,8 @@
198214
"cell_type": "markdown",
199215
"metadata": {},
200216
"source": [
217+
"Tip: **book2stats** is a dictionary mapping a book name (the key), e.g., ‘AnnaKarenina’, to a dictionary (the value) (the output from get_basic_stats)\n",
218+
"\n",
201219
"Tip: please use the following code snippet to obtain the basename name of a file path:"
202220
]
203221
},
@@ -266,7 +284,7 @@
266284
"and \n",
267285
"..\n",
268286
"```\n",
269-
"The following code snippet can help you with obtaining the top 20 occurring tokens."
287+
"The following code snippet can help you with obtaining the top 20 occurring tokens. The goal is to call the function you updated in Exercise 4a, i.e., get_basic_stats, in the file analyze.py. This also makes it possible to write the top 20 tokens to files."
270288
]
271289
},
272290
{
@@ -318,7 +336,7 @@
318336
"name": "python",
319337
"nbconvert_exporter": "python",
320338
"pygments_lexer": "ipython3",
321-
"version": "3.7.2"
339+
"version": "3.6.8"
322340
}
323341
},
324342
"nbformat": 4,

0 commit comments

Comments
 (0)