Method: ClassifierReborn::Bayes#initialize

Defined in:
lib/classifier-reborn/bayes.rb

#initialize(*args) ⇒ Bayes

The class can be created with one or more categories, each of which will be initialized and given a training method. E.g.,

b = ClassifierReborn::Bayes.new 'Interesting', 'Uninteresting', 'Spam'

Options available are:

language:         'en'   Used to select language specific stop words
auto_categorize:  false  When true, enables ability to dynamically declare a category
enable_threshold: false  When true, enables a threshold requirement for classifition
threshold:        0.0    Default threshold, only used when enabled


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/classifier-reborn/bayes.rb', line 20

def initialize(*args)
  @categories = Hash.new
  options = { language:         'en', 
              auto_categorize:  false,
              enable_threshold: false,
              threshold:        0.0
            }
  args.flatten.each { |arg|
    if arg.kind_of?(Hash)
      options.merge!(arg)
    else
      add_category(arg)
    end
  }

  @total_words         = 0
  @category_counts     = Hash.new(0)
  @category_word_count = Hash.new(0)

  @language            = options[:language]
  @auto_categorize     = options[:auto_categorize]
  @enable_threshold    = options[:enable_threshold]
  @threshold           = options[:threshold]
end