Class: Semantic::Search

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

Instance Method Summary collapse

Constructor Details

#initialize(documents, options = {}) ⇒ Search

Returns a new instance of Search.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/semantic/search.rb', line 4

def initialize(documents, options={})
  Semantic.logger.level = Logger::INFO if options[:verbose]
  
  @builder = VectorSpace::Builder.new(options)
  @matrix_transformer = MatrixTransformer.new(options)

  @vector_space_model = @builder.build_document_matrix(documents)
  
  Semantic.logger.info(@vector_space_model)
  
  @vector_space_model = @matrix_transformer.apply_transforms(@vector_space_model)
end

Instance Method Details



17
18
19
20
21
22
23
# File 'lib/semantic/search.rb', line 17

def related(documentId)
  ratings = []
  for index in (0...@vector_space_model.ncol)
    ratings << Compare.similarity(@vector_space_model.column(documentId), @vector_space_model.column(index))
  end
  ratings
end

#search(searchList) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/semantic/search.rb', line 25

def search(searchList)
  ratings = []
  query_vector = @builder.build_query_vector(searchList)
  for index in (0...@vector_space_model.ncol)
    ratings << Compare.similarity(query_vector, @vector_space_model.column(index))
  end
  ratings
end