Conversation
poosomooso
left a comment
There was a problem hiding this comment.
Nice project overall (Of course I was there for a fair bit of it)! One thing I noticed is that there is not a lot of comments. One good thing to do for all your functions is a comment (or docstring) under the line "def " describing what the function does, what it takes as a parameter, and what it returns (if it returns). Also lines like "line = line.replace('-', ' ')" in the process_line function, where it's not obvious what you intend, would benefit from having a brief comment explaining why that line is necessary. In that example, I have no idea why you are replacing all the dashes with spaces.
A small stylistic thing, but generally you want to put "imports" at the top of your code, so that someone glancing at it can see all the modules your code needs right at the beginning.
Nice job combing through the pattern documentation and finding other methods to help you analyze the text!
One more thing--if you find yourself copying/pasting a lot and changing only one variable, considering turning the block of code that you are copy/pasting into a function. In your project, you could write a function that takes in a file name of the book you want to analyze as a parameter, and that function could open the file from the parameter, and print the sentiment, mood, and modality. Having a function can help you avoid having multiple blocks of identical code, and can make your intentions much clearer to someone reading your code!
Again, good first project. When doing revisions, if you need me to clarify anything, I would be happy to! Conveying ideas is hard over text.
|
Hey Jonathan! Some less first-pass comments. Starting from your writeup--in your implementation, it would be nice to go more in depth into the code itself. Like how you used the the specific functions you wrote and why you wrote them, and how you achieved certain things, like making the histogram. Also, next time, put your write-up in a pdf, a .txt file, or a .md (markdown) file, just so we have a standard in this class. In general, you could still comment your code more. For example, inside your 'most_common' function, you should have a small comment explaining the what the for loop is for and maybe why you are using it. Or in 'process_line,' explain 'hist[word] = hist.get(word, 0) + 1,' since that line just looks like a jumble of letters and numbers. Your functions should also have docstrings instead of normal comments. So, instead of #function that takes a file and creates a histogram of the lines in a file you should have: def process_file(filename): It seems trivial, but it's something that people reading your code will look for, and doctests go in docstrings. Otherwise, your code is pretty straightforward and clean, and it definitely works. Nice job! |
No description provided.