Class: VaderSentimentRuby::SentimentIntensityAnalyzer

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

Overview

Returns a sentiment intensity score for sentences.

Instance Method Summary collapse

Constructor Details

#initializeSentimentIntensityAnalyzer



6
7
8
9
# File 'lib/vader_sentiment_ruby/sentiment_intensity_analyzer.rb', line 6

def initialize
  @lexicon = LexiconDictionaryCreator.new.call
  @emojis = EmojisDictionaryCreator.new.call
end

Instance Method Details

#polarity_scores(text) ⇒ Hash

Returns a float for sentiment strength based on the input text. Positive values are positive valence, negative value are negative valence.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vader_sentiment_ruby/sentiment_intensity_analyzer.rb', line 15

def polarity_scores(text)
  text = EmojiDescriber.new(text, @emojis).call
  senti_text = SentimentPropertiesIdentifier.new(text)

  sentiments = []
  words_and_emoticons = senti_text.words_and_emoticons
  words_and_emoticons.each_with_index do |item, index|
    sentiments << prepare_valence(item, index, words_and_emoticons, senti_text)
  end

  sentiments = Checker::ButWordNegationChecker.new(words_and_emoticons, sentiments).call

  ValenceScoreCalculator.new(sentiments, text).call
end