Class: VaderSentimentRuby::ValenceScoreCalculator

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

Overview

Prepares response with semantic score

Constant Summary collapse

DEFAULT_RESPONSE =
{
  negative: 0.0,
  neutral: 0.0,
  positive: 0.0,
  compound: 0.0
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(sentiments, text) ⇒ ValenceScoreCalculator

Returns a new instance of ValenceScoreCalculator.



13
14
15
16
# File 'lib/vader_sentiment_ruby/valence_score_calculator.rb', line 13

def initialize(sentiments, text)
  @sentiments = sentiments
  @text = text
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/vader_sentiment_ruby/valence_score_calculator.rb', line 18

def call
  return DEFAULT_RESPONSE unless @sentiments

  sum_s = @sentiments.map(&:to_f).sum
  # compute and add emphasis from punctuation in text
  punct_emph_amplifier = PunctuationEmphasisAmplifier.new(@text).call
  compound = normalize(sum_s, punct_emph_amplifier)

  prepare_response(compound, punct_emph_amplifier)
end