class VaderSentimentRuby::SentimentScoresSifter
Separates positive versus negative sentiment scores
Public Class Methods
new(sentiments)
click to toggle source
@param [Array<Float>] sentiments Array of sentiments generated from words
# 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
Public Instance Methods
call()
click to toggle source
@return [Array<Float, Float, Integer>] @example
[2.3, -3.2, 3]
# 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