vendor/bundle/ruby/2.5.0/gems/classifier-reborn-2.2.0/lib/classifier-reborn/bayes.rb
# Returns the scores in each category the provided +text+. E.g.,
#    b.classifications "I hate bad words and you"
#    =>  {"Uninteresting"=>-12.6997928013932, "Interesting"=>-18.4206807439524}
# The largest of these scores (the one closest to 0) is the one picked out by #classify
Returns the scores in each category the provided +text+.
Returns the scores in each category the provided + text + .
def classifications(text)
      score = {}
      word_hash = Hasher.word_hash(text, @language, @enable_stemmer)
      if word_hash.empty?
        category_keys.each do |category|
          score[category.to_s] = Float::INFINITY
        end
        return score
      end
      category_keys.each do |category|
        score[category.to_s] = 0
        total = (@backend.category_word_count(category) || 1).to_f
        word_hash.each do |word, _count|
          s = @backend.word_in_category?(category, word) ? @backend.category_word_frequency(category, word) : 0.1
          score[category.to_s] += Math.log(s / total)
        end
        s = @backend.category_has_trainings?(category) ? @backend.category_training_count(category) : 0.1
        score[category.to_s] += Math.log(s / @backend.total_trainings.to_f)
      end
      score
    end
def classifications ( text ) score = { } word_hash = Hasher . word_hash ( text , @language , @enable_stemmer ) if word_hash . empty? category_keys . each do | category | score [ category . to_s ] = Float :: INFINITY end return score end category_keys . each do | category | score [ category . to_s ] = 0 total = ( @backend . category_word_count ( category ) || 1 ) . to_f word_hash . each do | word , _count | s = @backend . word_in_category? ( category , word ) ? @backend . category_word_frequency ( category , word ) : 0.1 score [ category . to_s ] += Math . log ( s / total ) end s = @backend . category_has_trainings? ( category ) ? @backend . category_training_count ( category ) : 0.1 score [ category . to_s ] += Math . log ( s / @backend . total_trainings . to_f ) end score end
Returns the scores in each category the provided +text+.
Returns the scores in each category the provided + text + .
# now add prior probability for the category
text
<not_specific>