Reputation: 51
I know you can add your own words by manually adding them to the vader_lexicon.txt file. I was wondering if there was another way that you can do it in the python code as I don't want people who use my code need to then go modify other .txt files.
from nltk.sentiment.vader import SentimentIntensityAnalyzer as SIA
sia = SIA()
sia.lexicon
This will get the dict. Was thinking something like:
sia.lexicon.update{u'word': 3}
Upvotes: 0
Views: 2898
Reputation: 51
I think this is the answer.
sia.lexicon.update({u'word': 3.1})
Upvotes: 0
Reputation: 784
For anyone else:
from nltk.sentiment.vader import SentimentIntensityAnalyzer
new_words = {
'foo': 2.0,
'bar': -3.4,
}
SIA = SentimentIntensityAnalyzer()
SIA.lexicon.update(new_words)
Upvotes: 4