Class: VaderSentimentRuby::SentimentScoresSifter
- Inherits:
-
Object
- Object
- VaderSentimentRuby::SentimentScoresSifter
- Defined in:
- lib/vader_sentiment_ruby/sentiment_scores_sifter.rb
Overview
Separates positive versus negative sentiment scores
Instance Method Summary collapse
- #call ⇒ Array<Float, Float, Integer>
-
#initialize(sentiments) ⇒ SentimentScoresSifter
constructor
A new instance of SentimentScoresSifter.
Constructor Details
#initialize(sentiments) ⇒ SentimentScoresSifter
Returns a new instance of SentimentScoresSifter.
7 8 9 10 11 12 |
# File 'lib/vader_sentiment_ruby/sentiment_scores_sifter.rb', line 7 def initialize(sentiments) @sentiments = sentiments @pos_sum = 0.0 @neg_sum = 0.0 @neu_count = 0 end |
Instance Method Details
#call ⇒ Array<Float, Float, Integer>
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vader_sentiment_ruby/sentiment_scores_sifter.rb', line 17 def call @sentiments.each do |sentiment_score| # compensates for neutral words that are counted as 1 @pos_sum += sentiment_score.to_f + 1 if sentiment_score.positive? # when used with .abs, compensates for neutrals @neg_sum += sentiment_score.to_f - 1 if sentiment_score.negative? @neu_count += 1 if sentiment_score.zero? end [@pos_sum, @neg_sum, @neu_count] end |