Hot answers tagged

5

Maybe a simple typo in tweets here score = analyzer.analyze(tweets), since you want to send one tweet at a time. Also, beware here: token.lower(). The lower method returns the string in lower case, it does not change the string to lower case. You might try ./smile LOVE or ./smile HATE to see what result you get.


4

Make sure you're running flask in the same terminal window in which you exported the keys.


3

Try it without the '@' prefix. get_user_timeline calls twitter.lookup_user(). The example in the twitter API doc shows screen_name without the '@' in the example.


3

The [expression_using_X for X in Y] is evaluating expression_using_X for every X being an element of Y, and the [] make that list of expression values a Python list. squares = [x**2 for x in range(11)] would for example create a list of square numbers, from 0 to 100. tweet["text"] indicates that tweet (an element of tweets) is a dict, and has a property "...


2

This line token.lower() does not change token to lower case, it returns a copy of token in lower case. You can either set something to that return value (as with word = token.lower()) and then test for word in the arrays, or change the test(s) from if token in self.positives: to if token.lower() in self.positives:


1

Looks like unbalanced parentheses in the line above the elif.


1

The most serious error I see in the first view is on the next line: file = open(positives, "r") keep in mind that both positives and negatives are variables that are meant to be a (disordered) set of lines that will later be analyzed for positive or negative words, but still contains nothing, what we have to do is open the actual file on disk (like fopen ...


1

This syntax if word.lower() in self.positives == True: is the problem. Use if word.lower() in self.positives (without the equality). I don't remember the exact evaluation/operator precedence rules that apply.


1

elif text.lower() in self.neg_words: shouldn't that be token.lower()?


1

TweetTokenizer is a class in the nltk.tokenize.casual module. When you use the name of the class as a function, like: tokenizer = TweetTokenizer() that function, in Object Oriented Languages, is called the "constructor" of the class, because it "constructs" an object of that class. Classes can have static functions, which are functions you can call, ...


1

The problem is get_user_timeline because it returns a list of strings i.e you can't just pass it to the tokenize function. Instead you have to iterate over the strings and tokenize them seperatly.


Only top voted, non community-wiki answers of a minimum length are eligible