Class: Model

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_text: base_text) ⇒ Model

Returns a new instance of Model.



7
8
9
# File 'lib/model.rb', line 7

def initialize(base_text: base_text)
  @tf = train(words(File.read(base_text)))
end

Instance Attribute Details

#tfObject (readonly)

++ Term-Frequency ++



5
6
7
# File 'lib/model.rb', line 5

def tf
  @tf
end

Instance Method Details

#train(words) ⇒ Object

++ Term-Frequency count ++



21
22
23
24
25
# File 'lib/model.rb', line 21

def train(words)
  model = Hash.new(1)
  words.each {|f| model[f] += 1 }
  model
end

#words(text) ⇒ Object

++ remove specail character ++



14
15
16
# File 'lib/model.rb', line 14

def words(text)
  text.downcase.scan(/[a-z]+/)
end