Class: VaderSentimentRuby::Checker::SentimentLadenIdiomsChecker

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

Overview

Not implemented check for sentiment laden idioms that don’t contain a lexicon word

Instance Method Summary collapse

Constructor Details

#initialize(valence, senti_text_lower) ⇒ SentimentLadenIdiomsChecker

Returns a new instance of SentimentLadenIdiomsChecker.



8
9
10
11
# File 'lib/vader_sentiment_ruby/checker/sentiment_laden_idioms_checker.rb', line 8

def initialize(valence, senti_text_lower)
  @valence = valence
  @senti_text_lower = senti_text_lower
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vader_sentiment_ruby/checker/sentiment_laden_idioms_checker.rb', line 13

def call
  idioms_valences = []
  valence = @valence

  Constants::SENTIMENT_LADEN_IDIOMS.each do |idiom|
    next unless @senti_text_lower.include?(idiom)

    valence = Constants::SENTIMENT_LADEN_IDIOMS[idiom]
    idioms_valences.push(valence)
  end

  valence = idioms_valences.sum / idioms_valences.size.to_f if idioms_valences.size.positive?

  valence
end