vendor/bundle/ruby/2.5.0/gems/classifier-reborn-2.2.0/lib/classifier-reborn/bayes.rb
# Provides a untraining method for all categories specified in Bayes#new
# Be very careful with this method.
#
# For example:
#     b = ClassifierReborn::Bayes.new 'This', 'That', 'the_other'
#     b.train :this, "This text"
#     b.untrain :this, "This text"
Provides a untraining method for all categories specified in Bayes#new
Be very careful with this method.


Provides a untraining method for all categories specified in Bayes#new Be very careful with this method .
def untrain(category, text)
      word_hash = Hasher.word_hash(text, @language, @enable_stemmer)
      return if word_hash.empty?
      category = CategoryNamer.prepare_name(category)
      word_hash.each do |word, count|
        next if @backend.total_words < 0
        orig = @backend.category_word_frequency(category, word) || 0
        @backend.update_category_word_frequency(category, word, -count)
        if @backend.category_word_frequency(category, word) <= 0
          @backend.delete_category_word(category, word)
          count = orig
        end
        @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
def untrain ( category , text ) word_hash = Hasher . word_hash ( text , @language , @enable_stemmer ) return if word_hash . empty? category = CategoryNamer . prepare_name ( category ) word_hash . each do | word , count | next if @backend . total_words < 0 orig = @backend . category_word_frequency ( category , word ) || 0 @backend . update_category_word_frequency ( category , word , - count ) if @backend . category_word_frequency ( category , word ) <= 0 @backend . delete_category_word ( category , word ) count = orig end @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
Provides a untraining method for all categories specified in Bayes#new
Be very careful with this method.
Provides a untraining method for all categories specified in Bayes#new Be very careful with this method .
category
<not_specific>
text
<not_specific>