Class: BayesMotel::Corpus
- Inherits:
-
Object
- Object
- BayesMotel::Corpus
- Defined in:
- lib/bayes_motel/corpus.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
-
#classify(doc) ⇒ Object
The default classification algorithm just picks the category with the highest score.
- #cleanup ⇒ Object
-
#initialize(name) ⇒ Corpus
constructor
A new instance of Corpus.
- #score(doc) ⇒ Object
- #train(doc, category) ⇒ Object
Constructor Details
#initialize(name) ⇒ Corpus
Returns a new instance of Corpus.
7 8 9 10 11 |
# File 'lib/bayes_motel/corpus.rb', line 7 def initialize(name) @name = name @total_count = 0 @data = {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/bayes_motel/corpus.rb', line 5 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/bayes_motel/corpus.rb', line 3 def name @name end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
4 5 6 |
# File 'lib/bayes_motel/corpus.rb', line 4 def total_count @total_count end |
Instance Method Details
#classify(doc) ⇒ Object
The default classification algorithm just picks the category with the highest score.
24 25 26 27 28 29 30 31 |
# File 'lib/bayes_motel/corpus.rb', line 24 def classify(doc) results = score(doc) max = [:none, 0] results.each_pair do |(k, v)| max = [k, v] if v > max[1] end max end |
#cleanup ⇒ Object
33 34 35 36 37 |
# File 'lib/bayes_motel/corpus.rb', line 33 def cleanup @data.each_pair do |k, v| clean(@data, k, v) end end |
#score(doc) ⇒ Object
18 19 20 |
# File 'lib/bayes_motel/corpus.rb', line 18 def score(doc) _score(doc) end |
#train(doc, category) ⇒ Object
13 14 15 16 |
# File 'lib/bayes_motel/corpus.rb', line 13 def train(doc, category) @total_count += 1 _training(doc, category) end |