Class: Classified::ClassifierBayes

Inherits:
Base
  • Object
show all
Defined in:
lib/classifiers/classifier_bayes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ClassifierBayes

Returns a new instance of ClassifierBayes.



6
7
8
9
10
# File 'lib/classifiers/classifier_bayes.rb', line 6

def initialize options = {}
  @options = { :classes => ['Positive', 'Negative']}.merge!(options)
  @classifier = ::Classifier::Bayes.new 'Positive', 'Negative'
  #@classifier = ::Classifier::Bayes.new options[:classes]
end

Instance Attribute Details

#classifierObject

Returns the value of attribute classifier.



5
6
7
# File 'lib/classifiers/classifier_bayes.rb', line 5

def classifier
  @classifier
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/classifiers/classifier_bayes.rb', line 5

def options
  @options
end

Instance Method Details

#classificationsObject



20
21
22
# File 'lib/classifiers/classifier_bayes.rb', line 20

def classifications
  @options[:classes]
end

#classify(text) ⇒ Object



16
17
18
# File 'lib/classifiers/classifier_bayes.rb', line 16

def classify text
  @classifier.classify text
end

#train(classification, text) ⇒ Object



12
13
14
# File 'lib/classifiers/classifier_bayes.rb', line 12

def train classification, text
  @classifier.send("train_#{classification.to_s}", text)
end

#transform(text) ⇒ Object



24
25
26
# File 'lib/classifiers/classifier_bayes.rb', line 24

def transform text
  text.to_s.capitalize
end