Class: Semantic::MatrixTransformer

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MatrixTransformer

Returns a new instance of MatrixTransformer.



4
5
6
7
# File 'lib/semantic/matrix_transformer.rb', line 4

def initialize(options={})
  @transforms = options[:transforms] || [:TFIDF, :LSA]
  @options = options
end

Instance Method Details

#apply_transforms(vector_space_model) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/semantic/matrix_transformer.rb', line 9

def apply_transforms(vector_space_model)
  @transforms.each do |transform|
    begin
      transform_class = Semantic::Transform.const_get(transform)
      Semantic.logger.info("Applying #{transform} transform")
      vector_space_model.matrix = transform_class.send(:transform, vector_space_model.matrix) if transform_class.respond_to?(:transform)
      Semantic.logger.info(vector_space_model)
    rescue Exception => e
      Semantic.logger.error("Error: Cannot perform transform: #{transform}")
      Semantic.logger.error(e)
    end
  end
  vector_space_model
end