Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/bayes/string.rb
Instance Method Summary collapse
- #split_words ⇒ Object
- #stopword? ⇒ Boolean
-
#word_hash ⇒ Object
Returns a Hash of words and their frequencies.
Instance Method Details
#split_words ⇒ Object
14 15 16 |
# File 'lib/bayes/string.rb', line 14 def split_words gsub(/[^\w\s]+/," ").split end |
#stopword? ⇒ Boolean
18 19 20 |
# File 'lib/bayes/string.rb', line 18 def stopword? STOPWORDS.include? self end |
#word_hash ⇒ Object
Returns a Hash of words and their frequencies
4 5 6 7 8 9 10 11 12 |
# File 'lib/bayes/string.rb', line 4 def word_hash split_words.each_with_object({}) do |word, hash| word.downcase! if !word.stopword? && word.length > 2 hash[word] ||= 0 hash[word] += 1 end end end |