Skip to content

Commit

Permalink
Return the status of the training/untraining when run (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibnesayeed authored and Ch4s3 committed Jan 18, 2017
1 parent 535d2d7 commit 4f9035c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/classifier-reborn/bayes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.,
Expand Down

0 comments on commit 4f9035c

Please sign in to comment.