Class: OmniCat::Classifiers::Base

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

Direct Known Subclasses

Bayes

Instance Method Summary collapse

Methods inherited from Base

#to_hash

Instance Method Details

#add_categories(names) ⇒ Object

Allows adding multiple classification categories

Parameters

  • names - Array of categories

Examples

# Add multiple categories for classification
bayes.add_categories(["positive", "negative", "neutral"])


14
15
16
# File 'lib/omnicat/classifiers/base.rb', line 14

def add_categories(names)
  names.each { |name| add_category(name) }
end

#classify_batch(docs) ⇒ Object

Classify the multiple documents at a time

Parameters

  • docs - Array of documents

Returns

  • result_set - Array of OmniCat::Result objects

Examples

# Classify multiple documents
bayes.classify_batch(["good documentation", "damn workin again"])
=>


49
50
51
# File 'lib/omnicat/classifiers/base.rb', line 49

def classify_batch(docs)
  docs.collect { |doc| classify(doc) }
end

#train_batch(category, docs) ⇒ Object

Train the desired category with multiple documents

Parameters

  • category - Name of the category from added categories list

  • docs - Array of documents

Examples

# Add multiple docs for training the category
bayes.train("positive", ["clear documentation", "good, very well"])
bayes.train("negative", ["bad interface", "damn"])


30
31
32
# File 'lib/omnicat/classifiers/base.rb', line 30

def train_batch(category, docs)
  docs.each { |doc| train(category, doc) }
end