ZAMYLA CHAN: Let's analyze some words. In this part of the problem, we're going to allow the user to pass in a word as a command line argument. And then we will analyze whether that word is generally positive, generally negative, or just neutral. So per this example, the word "love" is positive, so it returns a green smiley face. The word "hate" is negative, so it returns a red sad face. And then "Stanford" is, well neutral, so we'll return a yellow neutral face. So what do we have to do here? Well, first things first is that we read all of the distribution code carefully and make sure that we understand how that distribution code already lends itself to the workflow of the problem. Then we'll move into analyzer.py and learn how to initialize our Analyzer with the positive and negative words. Then we'll fill in the function, Analyze, and analyze the word that's passed in. Let's start with the distribution code. Starting with positive-words.txt and negative-words.txt, we'll see that these text files have comments preceded by semicolons before we get to the actual words. So all of the positive words and negative words are in lines, where each line ends with a new line. And some of those lines, potentially, are also blank. Next is the Smile file. So you'll notice that Smile doesn't have any sort of file extension after it. But based on the shebang at the very top, it says that it is Python. So in order to read it correctly, enable syntax highlighting for Python files. OK, so then you'll see that we import the class Analyzer Now we can move on to initializing the Analyzer. from the module Analyzer, and then the function Colored from the Termcolor package. So these will come in handy later. Then there's a main function that ensures that the user passes in the expected number of command line arguments. Then it analyzes the word, retrieving the score, and prints the result, colored accordingly. So Smile is already finished for us. What we're going to do is go into analyzer.py and fill in the functionality so that Smile works correctly. Analyzer has two functions, an Initialization function, which will load the positive and negative words, and then Analyze, which when we're done, will assign every word in the text a value, negative 1 for any negative words, zero for a neutral word, and 1 for a positive word. Finally, we're going to want to calculate the text's total score to determine whether it's positive, negative, or neutral. into some structure that allows us to keep track and search it. So let's look into lists, dicts, or sets-- up to you. Store those positive and negative words into self.positives and self.negatives respectively, making sure to omit any leading or trailing whitespace. So look into the Strip function to see how you can do this. Now also remember how when we opened the positive and negative word text files, there were all these comments at the top that started with semicolons. We don't want to include any of those. So look into the Startswith function to see how you can check whether or not to include that line or not. So once you've loaded those in, then let's analyze and move on to that function. We're going to be talking about tokens and tokenizers. In order to help us analyze these words, we're going to use a tokenizer. The tokenizer allows us to split up words into single tokens, where each individual token contains a single word. So we can instantiate our tokenizer as follows. So now let's talk about iteration. If I have some text file, then if I want to do something with every line in that text file, then I'm going to have a With statement opening that file and then simply iterating over by having the statement "for line in lines." And then I can do something to every line within that. Now that we have all of these tools at our disposal, let's go back to Analyze and iterate over all of our tokens. I'll give you a hint to look at the lower function here. Then we'll want to check to see if that token is a positive or a negative word. If it's in neither data structure, then that means that it's neutral. So assigning each word the appropriate integer value returned the final score to Smile. And with that you've finished analyzing the words. My name is Zamyla. And this was analyzer.py.