You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sentences are tokenized and tokens are assigned a numerical score
for their average sentiment. The total score is then used to
determine the overall sentiment in relation to the threshold.
For example, the default threshold is 0.0. If a sentence has
a score of 0, it is deemed "neutral". Higher than the thresold
is "positive", lower is "negative".
If you set the threshold to a non-zero amount, e.g. 0.25:
Positive scores are > 0.25
Neutral scores are -0.25 - 0.25
Negative scores are < -0.25
Usage
# Create an instance for usageanalyzer=Sentimental.new# Load the default sentiment dictionariesanalyzer.load_defaults# And/or load your own dictionariesanalyzer.load_senti_file('path/to/your/file.txt')# Set a global thresholdanalyzer.threshold=0.1# Use your analyzeranalyzer.sentiment'I love ruby'#=> :positiveanalyzer.sentiment'I like ruby'#=> :neutralanalyzer.sentiment'I really like ruby'#=> :positive# You can make new analyzers with individual thresholds:analyzer=Sentimental.new(threshold: 0.9)analyzer.sentiment'I love ruby'#=> :positiveanalyzer.sentiment'I like ruby'#=> :neutralanalyzer.sentiment'I really like ruby'#=> :neutral# Get the numerical score of a string:analyzer.score'I love ruby'#=> 0.925
Sentiment dictionaries
These are currently plain-text files containing whitespace-separated
scores and tokens, e.g.:
1.0 Awesome
0.0 Meh
-1.0 Horrible
N-grams
You can parse n-grams of words by specifying their max size in the initializer: