my code for tweets works perfectly, except that the tweets do not seem to have the right score. A "happy" tweet does not have a positive score, for instance. Why is that? For your reference, I returned the output of get_user_timeline to tweets_50.Thank you!!!

    for tweet in tweets_50:
        tokenizer = nltk.tokenize.TweetTokenizer(False)
        tokens = tokenizer.tokenize(tweet)
        score = 0
        for token in tokens:
            if token in positives:
                score = score + 1
            elif token in negatives:
                score = score - 1
        if score > 0.0:
            print(colored(score, "green"), colored(tweet, "green"))
        elif score < 0.0:
            print(colored(score, "red"), colored(tweet, "red"))
            print(colored(score, "yellow"), colored(tweet, "yellow"))

Looks like you forgot to instantiate an Analyzer object and score the tweet using analyze method. Without the rest of the code, I will speculate that positives and negatives are created this way:

positives = os.path.join(sys.path[0], "positive-words.txt")
negatives = os.path.join(sys.path[0], "negative-words.txt")

If that's the case, if token in positives: always returns False, ditto the elif. If that's not the case, please edit more of the program.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .