Reputation: 51
How can I use a lexicon file (i.e. NRC Emotion Lexicon) for sentiment analysis in Python?
Upvotes: 4
Views: 6231
Reputation: 1038
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
Upvotes: 0
Reputation: 59
Maybe this will help http://jonathansoma.com/lede/algorithms-2017/classes/more-text-analysis/nrc-emotional-lexicon/
import pandas as pd
filepath = "NRC-Emotion-Lexicon-v0.92/NRC-emotion-lexicon-wordlevel-alphabetized-v0.92.txt"
emolex_df = pd.read_csv(filepath, names=["word", "emotion", "association"], skiprows=45, sep='\t')
emolex_df.head(12)
Upvotes: 1