class Categories

Attributes

default[R]

Public Class Methods

new(args) click to toggle source
# File lib/NaiveText/Categories.rb, line 6
def initialize(args)
  @categories = args[:categories] || []
  @default = args[:default] || NullCategory.new
end

Public Instance Methods

each(&block) click to toggle source
# File lib/NaiveText/Categories.rb, line 15
def each(&block)
  @categories.each(&block)
end
p_apriori(category) click to toggle source
# File lib/NaiveText/Categories.rb, line 11
def p_apriori(category)
  calculate_apriori_propability_for(category)
end
total_word_count() click to toggle source
# File lib/NaiveText/Categories.rb, line 19
def total_word_count
  @categories.inject(0) { |count, category| count + category.word_count }
end

Private Instance Methods

calculate_apriori_propability_for(category) click to toggle source
# File lib/NaiveText/Categories.rb, line 25
def calculate_apriori_propability_for(category)
  sum_of_words = @categories.inject(0) { |sum, category| sum + category.word_count }
  category.word_count.to_f / sum_of_words
end