Class: Semantic::Search
- Inherits:
-
Object
- Object
- Semantic::Search
- Defined in:
- lib/semantic/search.rb
Instance Method Summary collapse
-
#initialize(documents, options = {}) ⇒ Search
constructor
A new instance of Search.
- #related(documentId) ⇒ Object
- #search(searchList) ⇒ Object
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, ={}) Semantic.logger.level = Logger::INFO if [:verbose] @builder = VectorSpace::Builder.new() @matrix_transformer = MatrixTransformer.new() @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
#related(documentId) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/semantic/search.rb', line 17 def (documentId) = [] for index in (0...@vector_space_model.ncol) << Compare.similarity(@vector_space_model.column(documentId), @vector_space_model.column(index)) end end |
#search(searchList) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/semantic/search.rb', line 25 def search(searchList) = [] query_vector = @builder.build_query_vector(searchList) for index in (0...@vector_space_model.ncol) << Compare.similarity(query_vector, @vector_space_model.column(index)) end end |