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.

Parameters:

  • sentiments (Array<Float, Integer>)

    Array of sentiments for text

  • text (String)


15
16
17
18
# File 'lib/vader_sentiment_ruby/valence_score_calculator.rb', line 15

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

Instance Method Details

#callHash<Float, Float, Float, Float>

Returns Semantic score response hash.

Returns:

  • (Hash<Float, Float, Float, Float>)

    Semantic score response hash



21
22
23
24
25
26
27
28
29
30
# File 'lib/vader_sentiment_ruby/valence_score_calculator.rb', line 21

def call
  return DEFAULT_RESPONSE if @sentiments.empty?

  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