问题
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}
回答1:
For anyone else:
from nltk.sentiment.vader import SentimentIntensityAnalyzer
new_words = {
'foo': 2.0,
'bar': -3.4,
}
SIA = SentimentIntensityAnalyzer()
SIA.lexicon.update(new_words)
回答2:
I think this is the answer.
sia.lexicon.update({u'word': 3.1})
来源:https://stackoverflow.com/questions/49863520/how-to-edit-nltks-vader-sentiment-lexicon-without-modifying-a-txt-file