In analyze, shouldn't you use self.positives, and not open the files again?
Now to the real problems: .lstrip(" ") does not remove the line break at the end of the line, you could use .strip() instead to remove all kinds of whitespace at both ends.
You are right, this is confusing and it's not in the documentation. Since you are new in Object Oriented Programming, I'll try to explain it as simple as I can.
In OOP, the main difference from a non-OOP language, is the existence of classes. Now you may think of a class, as you think of a struct (i.e. a group of variables that serve a common goal), but ...
Are you sure it's adding a space, and you're not just printing a space using print? Consider
Added " so it's clear where the token begins and ends. Is there an extra space?
Both single and double quotation marks in python are used to specify some string data.
"""This is a docstring, it's similar to what a comment is!""""
a = 'This is a string'
b = "I am Knuth's fan."
# Calling the function
# Everything in python is Object, even functions!
enclosing a set of characters inside a double quotes tells the interpreter to treat it as a string so you can perform the respective operations with it.
e.g. "Hello", "123", "5", "5df", etc.
In python array is referred to as a List and it is more flexible that C array as you can add and delete elements dynamically with no pre-definition of the size of list. ...
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.
That default value for neutral is merely a placeholder at the start. When you run application.py without implementing it, you see a graph that is 100% neutral. You should initialize those values differently once you begin filling in the appropriate code there.
As for your for loop, the logic is there for the variables, but there is one way of handling case ...
tokenize returns a list, therefore tokens is a list from tokens = tokenizer.tokenize(text). Even if text is only one word. If text is 'cat', tokens is ['cat'].
This if tokens==self.Pos[A]: can never be true (nor the analogous test on sef.Neg[B]) because you are comparing a list (tokens) to one member of a list (ie a single word Pos[A], Neg[B]).
You do ...
Here's a trick that might make the API_KEY/SECRET easier to manage. Create a new file in your sentiments directory (I call mine twitkeys). Type or copy/paste the two export commands into this file and save it. Your file will look something like
(of course your KEY and SECRET instead of whatever).
Yes, in the application.py you need to implement almost the same code as you have written in tweets.
load positive.file and negative.file into memory
analyze each tweet
positive = 0
negative = 0
neutral = 0
score = 0
for tweet in tweets:
score = analyzer.analyze(tweet)
if score > 0.0:
positive += 1
elif score < 0.0: