Sentiment analysis with NRC Emotion Lexicon in Python

Viewed 5034

How can I use a lexicon file (i.e. NRC Emotion Lexicon) for sentiment analysis in Python?

2 Answers

I would suggest that you have a look at this repository which provides some interfaces to the dictionary. Seems they also have a pypi

https://github.com/metalcorebear/NRCLex

from nrclex import NRCLex

#Instantiate text object (for best results, 'text' should be unicode).

text_object = NRCLex('text')

#Return words list.

text_object.words

#Return sentences list.

text_object.sentences

#Return affect list.

text_object.affect_list

#Return affect dictionary.

text_object.affect_dict

#Return raw emotional counts.

text_object.raw_emotion_scores

#Return highest emotions.

text_object.top_emotions

#Return affect frequencies.

text_object.affect_frequencies
Related