Class: Semantic::VectorSpace::Builder

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(options = {}) ⇒ Builder

Returns a new instance of Builder.



8
9
10
11
12
# File 'lib/semantic/vector_space/builder.rb', line 8

def initialize(options={})
  @parser = Parser.new
  @options = options
  @parsed_document_cache = []
end

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