Skip to content

Commit 4f9035c

Browse files
ibnesayeedCh4s3
authored andcommitted
Return the status of the training/untraining when run (jekyll#137)
1 parent 535d2d7 commit 4f9035c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/classifier-reborn/bayes.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ def train(category, text)
8080
end
8181
end
8282

83-
@backend.update_category_training_count(category, 1)
84-
@backend.update_total_trainings(1)
8583
word_hash.each do |word, count|
8684
@backend.update_category_word_frequency(category, word, count)
8785
@backend.update_category_word_count(category, count)
8886
@backend.update_total_words(count)
8987
end
88+
@backend.update_total_trainings(1)
89+
@backend.update_category_training_count(category, 1)
9090
end
9191

9292
# Provides a untraining method for all categories specified in Bayes#new
@@ -100,8 +100,6 @@ def untrain(category, text)
100100
word_hash = Hasher.word_hash(text, @language, @enable_stemmer)
101101
return if word_hash.empty?
102102
category = CategoryNamer.prepare_name(category)
103-
@backend.update_category_training_count(category, -1)
104-
@backend.update_total_trainings(-1)
105103
word_hash.each do |word, count|
106104
next if @backend.total_words < 0
107105
orig = @backend.category_word_frequency(category, word) || 0
@@ -114,6 +112,8 @@ def untrain(category, text)
114112
@backend.update_category_word_count(category, -count) if @backend.category_word_count(category) >= count
115113
@backend.update_total_words(-count)
116114
end
115+
@backend.update_total_trainings(-1)
116+
@backend.update_category_training_count(category, -1)
117117
end
118118

119119
# Returns the scores in each category the provided +text+. E.g.,

0 commit comments

Comments
 (0)