0

I'm trying to get ./smile to work before moving on to tweets using just one word as input to check it my words are loading correctly. I structured the first function similar to how it is done in lecture but it doesn't seem to be working. No matter what word I enter, I always receive a neutral face. Any ideas?

`

import nltk
 import pdb

class Analyzer():
"""Implements sentiment analysis."""

def __init__(self, positives, negatives):
    """Initialize Analyzer."""

    self.positives = set()
    self.negatives = set()

    #load positive words
    positiveWords = open("positive-words.txt", "r")
    for line in positiveWords:
        if not line.startswith(";") or line.startswith(" "):
            self.positives.add(line.rstrip("\n"))
        else:
            pass
    positiveWords.close()

    #load negative words
    negativeWords = open("negative-words.txt", "r")
    for line in negativeWords:
        if not line.startswith(";") or line.startswith(" "):
            self.negatives.add(line.rstrip("\n"))
        else:
            pass
    negativeWords.close()

def analyze(self, text):
    """Analyze text for sentiment, returning its score."""

    if text.lower() in self.positives == True:
        return 1
    elif text.lower() in self.negatives == True:
        return -1
    else:
        return 0

`

Thanks for your help!

1

Figured out myself... removed the == True comparison and it worked fine.

You must log in to answer this question.

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