Question: USE PYTHON Please explain it in details possibly with screenshots. **hm1_dir have 10 text files which needs to be read. Each file have a paragraph
USE PYTHON
Please explain it in details possibly with screenshots.
**hm1_dir have 10 text files which needs to be read. Each file have a paragraph of writing. Please give me sample code as to how it should be done. Thanks in advance :)
Objective: Use Python to read files from a directory and calculate frequency statistics on words.
Turn in: your Python code
Download the hm1_dir and save it in the same folder as your Python program. Within your main() function, get the directory name from a system argument. Print an appropriate error message if the sys.argv is missing and end the program.
In a for loop, (a) read in each file, (b) use the string.replace() method to replace newlines with spaces, (c) use the string.lower() method to lower case the text, then use NLTK tokenizer to extract tokens, (d) make a FreqDist from the tokens, (3) print the filename and 5 most common words, (e) on each iteration through the files, add the FreqDist to a cumulative FreqDist for later.
Repeat the same loop as above but add the following: (a) remove punctuation symbols before tokenizing, (b) remove stopwords.
For your cumulative FreqDist for steps 2 and 3, create a cumulative frequency graph of the 50 most common words. Note that you may have to install matplotlib, and the first time matplotlib runs it takes a while.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
