class VaderSentimentRuby::Checker::PreviousWordsInfluenceChecker

Checks if the preceding words increase, decrease, or negate/nullify the valence

Public Class Methods

new(word, valence, is_cap_diff) click to toggle source

@param [String] word @param [Float] valence @param [Boolean] is_cap_diff

# File lib/vader_sentiment_ruby/checker/previous_words_influence_checker.rb, line 10
def initialize(word, valence, is_cap_diff)
  @word = word
  @word_lower = word.downcase
  @valence = valence
  @is_cap_diff = is_cap_diff
  @scalar = 0.0
end

Public Instance Methods

call() click to toggle source

@return [Float]

# File lib/vader_sentiment_ruby/checker/previous_words_influence_checker.rb, line 19
def call
  return @scalar unless word_in_booster_dictionary?

  take_scalar_from_dictionary
  @scalar *= -1 if @valence.negative?
  amplify_scalar_by_word_case

  @scalar
end

Private Instance Methods

amplified_scalar() click to toggle source
# File lib/vader_sentiment_ruby/checker/previous_words_influence_checker.rb, line 46
def amplified_scalar
  if @valence.positive?
    @scalar += Constants::C_INCR
  else
    @scalar -= Constants::C_INCR
  end
end
amplify_scalar_by_word_case() click to toggle source
# File lib/vader_sentiment_ruby/checker/previous_words_influence_checker.rb, line 39
def amplify_scalar_by_word_case
  # Check if booster/dampener word is in ALLCAPS (while others aren't)
  return unless WordHelper.word_upcase?(@word) && @is_cap_diff

  amplified_scalar
end
take_scalar_from_dictionary() click to toggle source
# File lib/vader_sentiment_ruby/checker/previous_words_influence_checker.rb, line 35
def take_scalar_from_dictionary
  @scalar = Constants::BOOSTER_DICT[@word_lower]
end
word_in_booster_dictionary?() click to toggle source
# File lib/vader_sentiment_ruby/checker/previous_words_influence_checker.rb, line 31
def word_in_booster_dictionary?
  Constants::BOOSTER_DICT.keys.include?(@word_lower)
end