Created
July 20, 2022 16:44
-
-
Save avakn5/1abdf328d57fa7714ce73b1f28088cf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#implementing the Vader Sentiment Analysis, handily for almost the totality of the simple sentiment analysis | |
import nltk | |
nltk.download('vader_lexicon') | |
from nltk.sentiment.vader import SentimentIntensityAnalyzer | |
def sentiment_scores(sentence): | |
# Create a SentimentIntensityAnalyzer object. | |
sid_obj = SentimentIntensityAnalyzer() | |
# the sentiment dictionary contains pos, neg, neu, and compound scores. | |
sentiment_dict = sid_obj.polarity_scores(sentence) | |
print(sentiment_dict['neg']*100) | |
print(sentiment_dict['neu']*100) | |
print(sentiment_dict['pos']*100) | |
def sentiment_dictneg(phrase): | |
sid_obj = SentimentIntensityAnalyzer() | |
sentiment_dict = sid_obj.polarity_scores(phrase) | |
return sentiment_dict['neg']*100 | |
def sentiment_dictneu(phrase): | |
sid_obj = SentimentIntensityAnalyzer() | |
sentiment_dict = sid_obj.polarity_scores(phrase) | |
return sentiment_dict['neu']*100 | |
def sentiment_dictpos(phrase): | |
sid_obj = SentimentIntensityAnalyzer() | |
sentiment_dict = sid_obj.polarity_scores(phrase) | |
return sentiment_dict['pos']*100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment