From 57a2f81b822a3eca658327c52132f31671b4b6b5 Mon Sep 17 00:00:00 2001 From: Sawood Alam Date: Wed, 18 Jan 2017 00:02:29 -0500 Subject: [PATCH] Return the startus of the training/untraining when run --- lib/classifier-reborn/bayes.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/classifier-reborn/bayes.rb b/lib/classifier-reborn/bayes.rb index da3014e..7783506 100644 --- a/lib/classifier-reborn/bayes.rb +++ b/lib/classifier-reborn/bayes.rb @@ -80,13 +80,13 @@ def train(category, text) end end - @backend.update_category_training_count(category, 1) - @backend.update_total_trainings(1) word_hash.each do |word, count| @backend.update_category_word_frequency(category, word, count) @backend.update_category_word_count(category, count) @backend.update_total_words(count) end + @backend.update_total_trainings(1) + @backend.update_category_training_count(category, 1) end # Provides a untraining method for all categories specified in Bayes#new @@ -100,8 +100,6 @@ def untrain(category, text) word_hash = Hasher.word_hash(text, @language, @enable_stemmer) return if word_hash.empty? category = CategoryNamer.prepare_name(category) - @backend.update_category_training_count(category, -1) - @backend.update_total_trainings(-1) word_hash.each do |word, count| next if @backend.total_words < 0 orig = @backend.category_word_frequency(category, word) || 0 @@ -114,6 +112,8 @@ def untrain(category, text) @backend.update_category_word_count(category, -count) if @backend.category_word_count(category) >= count @backend.update_total_words(-count) end + @backend.update_total_trainings(-1) + @backend.update_category_training_count(category, -1) end # Returns the scores in each category the provided +text+. E.g.,