Class: RSemantic::Search
- Inherits:
-
Object
- Object
- RSemantic::Search
- Defined in:
- lib/rsemantic/search.rb
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
Instance Method Summary collapse
-
#initialize(documents, options = {}) ⇒ Search
constructor
A new instance of Search.
- #related(document_id) ⇒ Object
- #search(search_list) ⇒ Object
Constructor Details
#initialize(documents, options = {}) ⇒ Search
Returns a new instance of Search.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rsemantic/search.rb', line 5 def initialize(documents, = {}) = { :transforms => [:TFIDF, :LSA], :verbose => false, :filter_stop_words => true, :stem_words => true, }.merge() RSemantic.logger.level = [:verbose] ? Logger::INFO : Logger::ERROR @builder = VectorSpace::Builder.new( :filter_stop_words => [:filter_stop_words], :stem_words => [:stem_words], :locale => [:locale] ) @matrix_transformer = MatrixTransformer.new([:transforms]) @vector_space_model = @builder.build_document_matrix(documents) RSemantic.logger.info(@vector_space_model) @vector_space_model = @matrix_transformer.apply_transforms(@vector_space_model) end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
3 4 5 |
# File 'lib/rsemantic/search.rb', line 3 def builder @builder end |
Instance Method Details
#related(document_id) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rsemantic/search.rb', line 29 def (document_id) = [] @vector_space_model.each_column do |column| << Compare.similarity(@vector_space_model.column(document_id), column) end end |
#search(search_list) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/rsemantic/search.rb', line 37 def search(search_list) = [] query_vector = @builder.build_query_vector(search_list) @vector_space_model.each_column do |column| << Compare.similarity(query_vector.col, column) end end |