Class: OmniCat::Classifiers::Strategy

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

Overview

Author

Mustafa Turan ([email protected])

Copyright

Copyright © 2013 Mustafa Turan

License

MIT

The class supplies abstract methods for possible text classifiers

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_hash

Constructor Details

#initialize(strategy_hash = {}) ⇒ Strategy

Returns a new instance of Strategy.



19
20
21
22
23
24
25
26
# File 'lib/omnicat/classifiers/strategy.rb', line 19

def initialize(strategy_hash = {})
  @categories = ::OmniCat::Hash.new
  @category_count = strategy_hash[:category_count].to_i
  @category_size_limit = strategy_hash[:category_size_limit].to_i
  @doc_count = strategy_hash[:doc_count].to_i
  @token_count = strategy_hash[:token_count].to_i
  @uniq_token_count = strategy_hash[:uniq_token_count].to_i
end

Instance Attribute Details

#categoriesObject

::OmniCat::Hash - Hash of categories



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

def categories
  @categories
end

#category_countObject

Integer - Total category count



13
14
15
# File 'lib/omnicat/classifiers/strategy.rb', line 13

def category_count
  @category_count
end

#category_size_limitObject

Integer - Max allowed category



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

def category_size_limit
  @category_size_limit
end

#doc_countObject

Integer - Total token count



15
16
17
# File 'lib/omnicat/classifiers/strategy.rb', line 15

def doc_count
  @doc_count
end

#token_countObject

Integer - Total token count



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

def token_count
  @token_count
end

#uniq_token_countObject

Integer - Total uniq token count



17
18
19
# File 'lib/omnicat/classifiers/strategy.rb', line 17

def uniq_token_count
  @uniq_token_count
end

Instance Method Details

#add_categories(names) ⇒ Object

Allows adding multiple classification categories

Parameters

  • names - Array of categories



44
45
46
# File 'lib/omnicat/classifiers/strategy.rb', line 44

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

#add_category(name) ⇒ Object

Abstract method for adding new classification category

Parameters

  • name - Name for category



34
35
36
# File 'lib/omnicat/classifiers/strategy.rb', line 34

def add_category(name)
  not_implemented_error(__callee__)
end

#classify(doc) ⇒ Object

Abstract method for classifying the given document

Parameters

  • doc - The document for classification

Returns

  • result - OmniCat::Result object



102
103
104
# File 'lib/omnicat/classifiers/strategy.rb', line 102

def classify(doc)
  not_implemented_error(__callee__)
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



116
117
118
# File 'lib/omnicat/classifiers/strategy.rb', line 116

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

#train(category_name, doc) ⇒ Object

Abstract method for training the desired category with a document

Parameters

  • category - Name of the category from added categories list

  • doc - Document text



55
56
57
# File 'lib/omnicat/classifiers/strategy.rb', line 55

def train(category_name, doc)
  not_implemented_error(__callee__)
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



66
67
68
# File 'lib/omnicat/classifiers/strategy.rb', line 66

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

#untrain(category_name, doc) ⇒ Object

Abstract method for untraining the desired category with a document

Parameters

  • category - Name of the category from added categories list

  • doc - Document text



77
78
79
# File 'lib/omnicat/classifiers/strategy.rb', line 77

def untrain(category_name, doc)
  not_implemented_error(__callee__)
end

#untrain_batch(category, docs) ⇒ Object

Untrain the desired category with multiple documents

Parameters

  • category - Name of the category from added categories list

  • docs - Array of documents



88
89
90
# File 'lib/omnicat/classifiers/strategy.rb', line 88

def untrain_batch(category, docs)
  docs.each { |doc| untrain(category, doc) }
end