class VaderSentimentRuby::Checker::ButWordNegationChecker

Checks for modification in sentiment due to contrastive conjunction 'but'

Public Class Methods

new(words_and_emoticons, sentiments) click to toggle source
# File lib/vader_sentiment_ruby/checker/but_word_negation_checker.rb, line 7
def initialize(words_and_emoticons, sentiments)
  @words_and_emoticons_lower = words_and_emoticons.map { |w| w.to_s.downcase }
  @sentiments = sentiments
end

Public Instance Methods

call() click to toggle source
# File lib/vader_sentiment_ruby/checker/but_word_negation_checker.rb, line 12
def call
  return @sentiments unless @words_and_emoticons_lower.include?('but')

  but_index = @words_and_emoticons_lower.index('but')
  updated_sentiments = []
  @sentiments.each_with_index do |sentiment, senti_index|
    updated_sentiments << modified_sentiment(sentiment, senti_index, but_index)
  end

  updated_sentiments
end

Private Instance Methods

modified_sentiment(sentiment, senti_index, but_index) click to toggle source
# File lib/vader_sentiment_ruby/checker/but_word_negation_checker.rb, line 26
def modified_sentiment(sentiment, senti_index, but_index)
  return sentiment * 0.5 if senti_index < but_index
  return sentiment * 1.5 if senti_index > but_index

  sentiment
end