Class: NBayes::Vocab
- Inherits:
-
Object
- Object
- NBayes::Vocab
- Defined in:
- lib/nbayes.rb
Instance Attribute Summary collapse
-
#log_size ⇒ Object
Returns the value of attribute log_size.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
Instance Method Summary collapse
- #delete(token) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(options = {}) ⇒ Vocab
constructor
A new instance of Vocab.
- #seen_token(token) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Vocab
Returns a new instance of Vocab.
18 19 20 21 22 |
# File 'lib/nbayes.rb', line 18 def initialize( = {}) @tokens = Hash.new # for smoothing, use log of vocab size, rather than vocab size @log_size = [:log_size] end |
Instance Attribute Details
#log_size ⇒ Object
Returns the value of attribute log_size.
16 17 18 |
# File 'lib/nbayes.rb', line 16 def log_size @log_size end |
#tokens ⇒ Object
Returns the value of attribute tokens.
16 17 18 |
# File 'lib/nbayes.rb', line 16 def tokens @tokens end |
Instance Method Details
#delete(token) ⇒ Object
24 25 26 |
# File 'lib/nbayes.rb', line 24 def delete(token) tokens.delete(token) end |
#each(&block) ⇒ Object
28 29 30 |
# File 'lib/nbayes.rb', line 28 def each(&block) tokens.keys.each(&block) end |
#seen_token(token) ⇒ Object
40 41 42 |
# File 'lib/nbayes.rb', line 40 def seen_token(token) tokens[token] = 1 end |
#size ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/nbayes.rb', line 32 def size if log_size Math.log(tokens.count) else tokens.count end end |