Class: ClassifierReborn::BayesMemoryBackend
- Inherits:
-
Object
- Object
- ClassifierReborn::BayesMemoryBackend
- Defined in:
- lib/classifier-reborn/backends/bayes_memory_backend.rb
Instance Attribute Summary collapse
-
#total_trainings ⇒ Object
readonly
Returns the value of attribute total_trainings.
-
#total_words ⇒ Object
readonly
Returns the value of attribute total_words.
Instance Method Summary collapse
- #add_category(category) ⇒ Object
- #category_has_trainings?(category) ⇒ Boolean
- #category_keys ⇒ Object
- #category_training_count(category) ⇒ Object
- #category_word_count(category) ⇒ Object
- #category_word_frequency(category, word) ⇒ Object
- #delete_category_word(category, word) ⇒ Object
-
#initialize ⇒ BayesMemoryBackend
constructor
This class provides Memory as the storage backend for the classifier data structures.
- #reset ⇒ Object
- #update_category_training_count(category, diff) ⇒ Object
- #update_category_word_count(category, diff) ⇒ Object
- #update_category_word_frequency(category, word, diff) ⇒ Object
- #update_total_trainings(diff) ⇒ Object
- #update_total_words(diff) ⇒ Object
- #word_in_category?(category, word) ⇒ Boolean
Constructor Details
#initialize ⇒ BayesMemoryBackend
This class provides Memory as the storage backend for the classifier data structures
8 9 10 11 12 13 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 8 def initialize @total_words = 0 @total_trainings = 0 @category_counts = {} @categories = {} end |
Instance Attribute Details
#total_trainings ⇒ Object (readonly)
Returns the value of attribute total_trainings.
5 6 7 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 5 def total_trainings @total_trainings end |
#total_words ⇒ Object (readonly)
Returns the value of attribute total_words.
5 6 7 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 5 def total_words @total_words end |
Instance Method Details
#add_category(category) ⇒ Object
43 44 45 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 43 def add_category(category) @categories[category] ||= Hash.new(0) end |
#category_has_trainings?(category) ⇒ Boolean
31 32 33 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 31 def category_has_trainings?(category) @category_counts.key?(category) && category_training_count(category) > 0 end |
#category_keys ⇒ Object
47 48 49 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 47 def category_keys @categories.keys end |
#category_training_count(category) ⇒ Object
23 24 25 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 23 def category_training_count(category) category_counts(category)[:training] end |
#category_word_count(category) ⇒ Object
35 36 37 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 35 def category_word_count(category) category_counts(category)[:word] end |
#category_word_frequency(category, word) ⇒ Object
51 52 53 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 51 def category_word_frequency(category, word) @categories[category][word] end |
#delete_category_word(category, word) ⇒ Object
59 60 61 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 59 def delete_category_word(category, word) @categories[category].delete(word) end |
#reset ⇒ Object
67 68 69 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 67 def reset initialize end |
#update_category_training_count(category, diff) ⇒ Object
27 28 29 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 27 def update_category_training_count(category, diff) category_counts(category)[:training] += diff end |
#update_category_word_count(category, diff) ⇒ Object
39 40 41 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 39 def update_category_word_count(category, diff) category_counts(category)[:word] += diff end |
#update_category_word_frequency(category, word, diff) ⇒ Object
55 56 57 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 55 def update_category_word_frequency(category, word, diff) @categories[category][word] += diff end |
#update_total_trainings(diff) ⇒ Object
19 20 21 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 19 def update_total_trainings(diff) @total_trainings += diff end |
#update_total_words(diff) ⇒ Object
15 16 17 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 15 def update_total_words(diff) @total_words += diff end |
#word_in_category?(category, word) ⇒ Boolean
63 64 65 |
# File 'lib/classifier-reborn/backends/bayes_memory_backend.rb', line 63 def word_in_category?(category, word) @categories[category].key?(word) end |