Class: Model
- Inherits:
-
Object
- Object
- Model
- Defined in:
- lib/model.rb
Instance Attribute Summary collapse
-
#tf ⇒ Object
readonly
++ Term-Frequency ++.
Instance Method Summary collapse
-
#initialize(base_text: base_text) ⇒ Model
constructor
A new instance of Model.
-
#train(words) ⇒ Object
++ Term-Frequency count ++.
-
#words(text) ⇒ Object
++ remove specail character ++.
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
#tf ⇒ Object (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 |