Class: Ruigi::Model
- Inherits:
-
Object
- Object
- Ruigi::Model
- Defined in:
- lib/ruigi/model.rb
Instance Attribute Summary collapse
-
#corpus ⇒ Object
Returns the value of attribute corpus.
Instance Method Summary collapse
- #feature_vector_of(index) ⇒ Object
-
#initialize(corpus) ⇒ Model
constructor
A new instance of Model.
- #inner_product_matrix ⇒ Object
- #matrix ⇒ Object
- #wordlist ⇒ Object
Constructor Details
#initialize(corpus) ⇒ Model
Returns a new instance of Model.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/ruigi/model.rb', line 5 def initialize(corpus) raise TypeError unless corpus.is_a?(Array) raise TypeError unless corpus.all? { |e| e.is_a?(Ruigi::Document) } self.corpus = corpus corpus.each do |document| document.model = self end end |
Instance Attribute Details
#corpus ⇒ Object
Returns the value of attribute corpus.
3 4 5 |
# File 'lib/ruigi/model.rb', line 3 def corpus @corpus end |
Instance Method Details
#feature_vector_of(index) ⇒ Object
20 21 22 |
# File 'lib/ruigi/model.rb', line 20 def feature_vector_of(index) corpus[index].feature_vector.to_nm end |
#inner_product_matrix ⇒ Object
28 29 30 |
# File 'lib/ruigi/model.rb', line 28 def inner_product_matrix matrix.dot(matrix.transpose) end |
#matrix ⇒ Object
16 17 18 |
# File 'lib/ruigi/model.rb', line 16 def matrix @matrix ||= corpus.map(&:feature_vector).to_nm end |
#wordlist ⇒ Object
24 25 26 |
# File 'lib/ruigi/model.rb', line 24 def wordlist @wordlist ||= corpus.map { |document| document.words.keys }.flatten.uniq.sort end |