Class: Semantic::VectorSpace::Builder
- Inherits:
-
Object
- Object
- Semantic::VectorSpace::Builder
- Defined in:
- lib/semantic/vector_space/builder.rb
Overview
A algebraic model for representing text documents as vectors of identifiers. A document is represented as a vector. Each dimension of the vector corresponds to a separate term. If a term occurs in the document, then the value in the vector is non-zero.
Instance Method Summary collapse
- #build_document_matrix(documents) ⇒ Object
- #build_query_vector(term_list) ⇒ Object
-
#initialize(options = {}) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
Instance Method Details
#build_document_matrix(documents) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/semantic/vector_space/builder.rb', line 14 def build_document_matrix(documents) @vector_keyword_index = build_vector_keyword_index(documents) document_vectors = documents.enum_for(:each_with_index).map{|document,document_id| build_vector(document, document_id)} document_matrix = Linalg::DMatrix.join_columns(document_vectors) Model.new(document_matrix, @vector_keyword_index) end |
#build_query_vector(term_list) ⇒ Object
23 24 25 |
# File 'lib/semantic/vector_space/builder.rb', line 23 def build_query_vector(term_list) build_vector(term_list.join(" ")) end |