class VaderSentimentRuby::PunctuationEmphasisAmplifier

Adds emphasis factor from exclamation points and question marks

Constants

EXCLAMATION_MARK
EXCLAMATION_MARK_RATING_INCREASE

Empirically derived mean sentiment intensity rating increases for exclamation points and question marks

QUESTION_MARK
QUESTION_MARK_RATING_INCREASE

Public Class Methods

new(text) click to toggle source

@param [String] text

# File lib/vader_sentiment_ruby/punctuation_emphasis_amplifier.rb, line 13
def initialize(text)
  @text_array = text.split('')
end

Public Instance Methods

call() click to toggle source

@return [Float, Integer] Emphasis factor

# File lib/vader_sentiment_ruby/punctuation_emphasis_amplifier.rb, line 18
def call
  (amplify_exclamation_points + amplify_question_marks).round(3)
end

Private Instance Methods

amplify_exclamation_points() click to toggle source
# File lib/vader_sentiment_ruby/punctuation_emphasis_amplifier.rb, line 24
def amplify_exclamation_points
  # Check for added emphasis resulting from exclamation points (up to 4 of them)
  ep_count = @text_array.count(EXCLAMATION_MARK)
  ep_count = 4 if ep_count > 4

  ep_count * EXCLAMATION_MARK_RATING_INCREASE
end
amplify_question_marks() click to toggle source
# File lib/vader_sentiment_ruby/punctuation_emphasis_amplifier.rb, line 32
def amplify_question_marks
  # Check for added emphasis resulting from question marks (2 or 3+)
  qm_count = @text_array.count(QUESTION_MARK)

  return 0 unless qm_count > 1
  return 0.96 if qm_count > 3

  qm_count * QUESTION_MARK_RATING_INCREASE
end