Class: Classified::ClassifierBayes
- Defined in:
- lib/classifiers/classifier_bayes.rb
Instance Attribute Summary collapse
-
#classifier ⇒ Object
Returns the value of attribute classifier.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #classifications ⇒ Object
- #classify(text) ⇒ Object
-
#initialize(options = {}) ⇒ ClassifierBayes
constructor
A new instance of ClassifierBayes.
- #train(classification, text) ⇒ Object
- #transform(text) ⇒ Object
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 = { :classes => ['Positive', 'Negative']}.merge!() @classifier = ::Classifier::Bayes.new 'Positive', 'Negative' #@classifier = ::Classifier::Bayes.new options[:classes] end |
Instance Attribute Details
#classifier ⇒ Object
Returns the value of attribute classifier.
5 6 7 |
# File 'lib/classifiers/classifier_bayes.rb', line 5 def classifier @classifier end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/classifiers/classifier_bayes.rb', line 5 def @options end |
Instance Method Details
#classifications ⇒ Object
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 |