Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/bayes/string.rb

Instance Method Summary collapse

Instance Method Details

#split_wordsObject



14
15
16
# File 'lib/bayes/string.rb', line 14

def split_words
  gsub(/[^\w\s]+/," ").split
end

#stopword?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/bayes/string.rb', line 18

def stopword?
  STOPWORDS.include? self
end

#word_hashObject

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