I've checked over my code many times for errors, but everything looks logically sound to me. For some reason, "counter" in the analyze method will never change, which means that my conditional statements are not working properly. I don't see anything wrong with them though... I'd appreciate any help in finding the problem, either with my implementation of my two sets or my conditionals...
import nltk
class Analyzer():
"""Implements sentiment analysis."""
def __init__(self, positives, negatives):
"""Initialize Analyzer."""
self.positives = set()
self.negatives = set()
with open("positive-words.txt", "r") as file_pos:
for line in file_pos:
if line.startswith(";") == False:
self.positives.add(line.strip)
with open("negative-words.txt", "r") as file_neg:
for line in file_neg:
if line.startswith(";") == False:
self.negatives.add(line.strip)
file_pos.close()
file_neg.close()
def analyze(self, text):
"""Analyze text for sentiment, returning its score."""
score = 0
tokenizer = nltk.tokenize.TweetTokenizer()
tokens = tokenizer.tokenize(text)
for token in tokens:
if token.lower() in self.positives == True:
score = score + 1
elif token.lower() in self.negatives == True:
score = score - 1
print(score)
return score