Analyse Sentiment#
The analyze().sentiment
module performs sentiment analysis on text using the specified lexicon dictionary. It utilises a bag-of-words approach, analyzing the occurrence of terms without considering their order.
For score-based lexicons like VADER_v2014
, it sums the scores of matched terms and returns a single float/integer value reflecting overall sentiment. Higher scores indicate more positive/negative sentiment.
from sentibank.utils import analyze
# Analyse the sentiment
analyze = analyze()
text = "I am excited and happy about the new anouncement!"
result = analyze.sentiment(text=text, dictionary="VADER_v2014")
4.1
For label-based dictionaries like HarvardGI_v2000
, it counts matched terms per sentiment category and returns a dictionary of those label counts. The category with the most matches indicates the dominant overall sentiment.
from sentibank.utils import analyze
# Analyse the dictionary
analyze = analyze()
text = "I am excited and happy to make this anouncement to our shareholders."
result = analyze.sentiment(text=text, dictionary="MASTER_v2022")
{'Negative': 0,
'Uncertainty': 0,
'Constraining': 0,
'Positive': 2,
'Litigious': 0,
'Weak_Modal': 0,
'Strong_Modal': 0}