class VaderSentimentRuby::SentimentPropertiesIdentifier
Identify sentiment-relevant string-level properties of input text.
Attributes
is_cap_diff[R]
words_and_emoticons[R]
Public Class Methods
new(text)
click to toggle source
@param [String] text
# File lib/vader_sentiment_ruby/sentiment_properties_identifier.rb, line 9 def initialize(text) text = text.to_s.encode('utf-8') unless text.is_a? String @text = text @words_and_emoticons = prepare_words_and_emoticons # Doesn't separate words from adjacent punctuation (keeps emoticons & contractions) @is_cap_diff = text_contains_mixed_cases? end
Private Instance Methods
prepare_words_and_emoticons()
click to toggle source
Removes leading and trailing punctuation Leaves contractions and most emoticons @return [Array]
# File lib/vader_sentiment_ruby/sentiment_properties_identifier.rb, line 22 def prepare_words_and_emoticons @text .split .map { |word| WordHelper.strip_punctuation(word) } end
text_contains_mixed_cases?()
click to toggle source
Check whether just some words in the input are ALL CAPS. Returns `True` if some but not all items in `words` are ALL CAPS @return [Boolean]
# File lib/vader_sentiment_ruby/sentiment_properties_identifier.rb, line 31 def text_contains_mixed_cases? uppercase_words = @words_and_emoticons.count { |word| WordHelper.word_upcase?(word) } uppercase_words.positive? && uppercase_words < @words_and_emoticons.size end