Class: Bishop::BayesData

Inherits:
Object
  • Object
show all
Defined in:
lib/bishop.rb

Overview

Ruby’s YAML persists Hashes using special processing rather than by dumping it’s instance variables, hence no instance variables in a Hash subclass get dumped either <sigh>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = '', pool = nil) ⇒ BayesData

Returns a new instance of BayesData.



24
25
26
27
28
29
30
31
# File 'lib/bishop.rb', line 24

def initialize( name = '', pool = nil )
  @name = name
  @training = []
  @pool = pool
  @data = Hash.new( 0.0 )
  self.token_count = 0
  self.train_count = 0
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



22
23
24
# File 'lib/bishop.rb', line 22

def data
  @data
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/bishop.rb', line 21

def name
  @name
end

#token_countObject

Returns the value of attribute token_count.



21
22
23
# File 'lib/bishop.rb', line 21

def token_count
  @token_count
end

#train_countObject

Returns the value of attribute train_count.



21
22
23
# File 'lib/bishop.rb', line 21

def train_count
  @train_count
end

#trainingObject (readonly)

Returns the value of attribute training.



22
23
24
# File 'lib/bishop.rb', line 22

def training
  @training
end

Instance Method Details

#to_sObject



37
38
39
# File 'lib/bishop.rb', line 37

def to_s
  "<BayesDict: #{self.name || noname}, #{self.token_count} tokens>"
end

#trained_on?(item) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bishop.rb', line 33

def trained_on?( item )
  self.training.include? item
end