class ClassifierReborn::BayesMemoryBackend
Attributes
total_trainings[R]
total_words[R]
Public Class Methods
new()
click to toggle source
This class provides Memory as the storage backend for the classifier data structures
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 6 def initialize @total_words = 0 @total_trainings = 0 @category_counts = {} @categories = {} end
Public Instance Methods
add_category(category)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 41 def add_category(category) @categories[category] ||= Hash.new(0) end
category_has_trainings?(category)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 29 def category_has_trainings?(category) @category_counts.key?(category) && category_training_count(category) > 0 end
category_keys()
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 45 def category_keys @categories.keys end
category_training_count(category)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 21 def category_training_count(category) category_counts(category)[:training] end
category_word_count(category)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 33 def category_word_count(category) category_counts(category)[:word] end
category_word_frequency(category, word)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 49 def category_word_frequency(category, word) @categories[category][word] end
delete_category_word(category, word)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 57 def delete_category_word(category, word) @categories[category].delete(word) end
reset()
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 65 def reset initialize end
update_category_training_count(category, diff)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 25 def update_category_training_count(category, diff) category_counts(category)[:training] += diff end
update_category_word_count(category, diff)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 37 def update_category_word_count(category, diff) category_counts(category)[:word] += diff end
update_category_word_frequency(category, word, diff)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 53 def update_category_word_frequency(category, word, diff) @categories[category][word] += diff end
update_total_trainings(diff)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 17 def update_total_trainings(diff) @total_trainings += diff end
update_total_words(diff)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 13 def update_total_words(diff) @total_words += diff end
word_in_category?(category, word)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 61 def word_in_category?(category, word) @categories[category].key?(word) end
Private Instance Methods
category_counts(category)
click to toggle source
# File lib/classifier-reborn/backends/bayes_memory_backend.rb, line 71 def category_counts(category) @category_counts[category] ||= {training: 0, word: 0} end