Class: VaderSentimentRuby::PunctuationEmphasisAmplifier
- Inherits:
-
Object
- Object
- VaderSentimentRuby::PunctuationEmphasisAmplifier
- Defined in:
- lib/vader_sentiment_ruby/punctuation_emphasis_amplifier.rb
Overview
Adds emphasis from exclamation points and question marks
Instance Method Summary collapse
- #amplify_exclamation_points ⇒ Object
- #amplify_question_marks ⇒ Object
- #call ⇒ Float
-
#initialize(text) ⇒ PunctuationEmphasisAmplifier
constructor
A new instance of PunctuationEmphasisAmplifier.
Constructor Details
#initialize(text) ⇒ PunctuationEmphasisAmplifier
Returns a new instance of PunctuationEmphasisAmplifier.
7 8 9 |
# File 'lib/vader_sentiment_ruby/punctuation_emphasis_amplifier.rb', line 7 def initialize(text) @text = text end |
Instance Method Details
#amplify_exclamation_points ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/vader_sentiment_ruby/punctuation_emphasis_amplifier.rb', line 16 def amplify_exclamation_points # check for added emphasis resulting from exclamation points (up to 4 of them) ep_count = @text.split('').count('!') ep_count = 4.0 if ep_count > 4 # empirically derived mean sentiment intensity rating increase for exclamation points ep_count * 0.292 end |
#amplify_question_marks ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vader_sentiment_ruby/punctuation_emphasis_amplifier.rb', line 25 def amplify_question_marks # check for added emphasis resulting from question marks (2 or 3+) qm_count = @text.split('').count('?') return 0.0 unless qm_count > 1 # empirically derived mean sentiment intensity rating increase for question marks return qm_count * 0.18 if qm_count <= 3 0.96 end |
#call ⇒ Float
12 13 14 |
# File 'lib/vader_sentiment_ruby/punctuation_emphasis_amplifier.rb', line 12 def call amplify_exclamation_points + amplify_question_marks end |