Class: VaderSentimentRuby::Checker::NoWordChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/vader_sentiment_ruby/checker/no_word_checker.rb

Overview

Check for “no” as negation for an adjacent lexicon item vs “no” as its own stand-alone lexicon item

Instance Method Summary collapse

Constructor Details

#initialize(valence, item_lowercase, index, words_and_emoticons, lexicon) ⇒ NoWordChecker

Returns a new instance of NoWordChecker.

Parameters:

  • valence (Float)
  • item_lowercase (String)
  • index (Integer)
  • words_and_emoticons (Array)
  • lexicon (Hash)


12
13
14
15
16
17
18
# File 'lib/vader_sentiment_ruby/checker/no_word_checker.rb', line 12

def initialize(valence, item_lowercase, index, words_and_emoticons, lexicon)
  @valence = valence
  @item_lowercase = item_lowercase
  @index = index
  @words_and_emoticons = words_and_emoticons
  @lexicon = lexicon
end

Instance Method Details

#callFloat

Returns:

  • (Float)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vader_sentiment_ruby/checker/no_word_checker.rb', line 21

def call
  valence = @valence

  if @item_lowercase == 'no' &&
     @index != @words_and_emoticons.size - 1 &&
     @lexicon.keys.include?(@words_and_emoticons[@index + 1].downcase)
    # don't use valence of "no" as a lexicon item. Instead set it's valence to 0.0 and negate the next item
    valence = 0.0
  end

  valence = @lexicon[@item_lowercase] * Constants::N_SCALAR if one_of_preceding_words_is_no?

  valence
end