Class: VaderSentimentRuby::ValenceScoreCalculator
- Inherits:
-
Object
- Object
- VaderSentimentRuby::ValenceScoreCalculator
- 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
-
#call ⇒ Hash<Float, Float, Float, Float>
Semantic score response hash.
-
#initialize(sentiments, text) ⇒ ValenceScoreCalculator
constructor
A new instance of ValenceScoreCalculator.
Constructor Details
#initialize(sentiments, text) ⇒ ValenceScoreCalculator
Returns a new instance of ValenceScoreCalculator.
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
#call ⇒ Hash<Float, Float, Float, Float>
Returns 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 |