Module: VaderSentimentRuby::WordHelper
- Defined in:
- lib/vader_sentiment_ruby/word_helper.rb
Overview
Helper module for word manipulations to simulate pythons methods behavior word_upcase?(word) is similar to Python’s word.isupper() strip_punctuation(word) is similar to Python’s word.strip(string.punctuation)
Constant Summary collapse
- PUNCTUATIONS =
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
Class Method Summary collapse
-
.strip_punctuation(token) ⇒ String
Removes all trailing and leading punctuation If the resulting string has two or fewer characters, then it was likely an emoticon, so return original string (ie ‘:)’ stripped would be ”, so just return ‘:)’ Example strip_punctuation(“‘test’”) # => “test” strip_punctuation(“‘don’t’”) # => “don’t” strip_punctuation(“:)”) # => “:)”.
-
.word_upcase?(word) ⇒ Boolean
Checks that string contains at least one letter and all letters are in upcase Example word_upcase?(‘:D’) # => true word_upcase?(‘:)’) # => false.
Class Method Details
.strip_punctuation(token) ⇒ String
Removes all trailing and leading punctuation If the resulting string has two or fewer characters, then it was likely an emoticon, so return original string (ie ‘:)’ stripped would be ”, so just return ‘:)’ Example
strip_punctuation("'test'") # => "test"
strip_punctuation("'don't'") # => "don't"
strip_punctuation(":)") # => ":)"
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vader_sentiment_ruby/word_helper.rb', line 33 def strip_punctuation(token) token_without_punctuation = replace_punctuations(token) original_set = token.split('') updated_set = token_without_punctuation.split('') pair_array = prepare_match_array(original_set, updated_set) pair_array = clean_leading_punctuations(pair_array) pair_array = clean_trailing_punctuations(pair_array) stripped = pair_array.map { |item| item[:old_ch] }.join return token if stripped.size <= 2 stripped end |
.word_upcase?(word) ⇒ Boolean
Checks that string contains at least one letter and all letters are in upcase Example
word_upcase?(':D') # => true
word_upcase?(':)') # => false
18 19 20 |
# File 'lib/vader_sentiment_ruby/word_helper.rb', line 18 def word_upcase?(word) word == word.upcase && word.count('A-Za-z').positive? end |