just started this and have quite a bit trouble getting used to python despite having read all the courseware. My code keeps returning a neutral face. What is wrong? Thanks.
import nltk class Analyzer(): """Implements sentiment analysis.""" def __init__(self, positives, negatives): """Initialize Analyzer.""" #instantiate analyzer #create two sets to hold the words self.positives = set() self.negatives = set() #open each file #read each file line by line, removing extra space and comments #for positives with open(positives) as pfile: for line in pfile: if not line.startswith(";"): line = line.strip() self.positives.add(line) #for negatives with open(negatives) as nfile: for line in nfile: if not line.startswith(";"): line = line.strip() self.negatives.add(line) def analyze(self, text): """Analyze text for sentiment, returning its score.""" #initialise score as 0 score = 0 #tokenize the text with help from nltk tokenizer = nltk.tokenize.TweetTokenizer() tokens = tokenizer.tokenize(text) #make all the words in token lower case for i in range(len(tokens)): if tokens[i].lower in self.positives: score += 1 for i in range(len(tokens)): if tokens[i].lower in self.negatives: score -= 1 return score