class String

Constants

STOPWORDS

Public Instance Methods

split_words() click to toggle source
# File lib/bayes/string.rb, line 14
def split_words
  gsub(/[^\w\s]+/," ").split
end
stopword?() click to toggle source
# File lib/bayes/string.rb, line 18
def stopword?
  STOPWORDS.include? self
end
word_hash() click to toggle source

Returns a Hash of words and their frequencies

# 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