Class: RSemantic::VectorSpace::Model

Inherits:
GSL::Matrix
  • Object
show all
Defined in:
lib/rsemantic/vector_space/model.rb

Instance Method Summary collapse

Constructor Details

#initialize(matrix, keywords) ⇒ Model

Returns a new instance of Model.


9
10
11
12
13
# File 'lib/rsemantic/vector_space/model.rb', line 9

def initialize(matrix, keywords)
  @keywords = keywords || {}
  @_dc_obj = matrix
  super(matrix)
end

Instance Method Details

#matrixObject


19
20
21
# File 'lib/rsemantic/vector_space/model.rb', line 19

def matrix
  @_dc_obj
end

#matrix=(matrix) ⇒ Object


15
16
17
# File 'lib/rsemantic/vector_space/model.rb', line 15

def matrix=(matrix)
  @_dc_obj = matrix
end

#to_sObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rsemantic/vector_space/model.rb', line 23

def to_s
  out = StringIO.new
  out.print " " * 12

  matrix.size2.times do |id|
    out.print "  D#{id+1}  "
  end
  out.puts

  matrix.to_a.each_with_index do |terms, index|

    if @keywords.has_value?(index)
      index_position = @keywords.values.index(index)
      key = @keywords.keys[index_position]

      out.print "#{key.ljust(10)}"
    end
    out.print "[ "

    terms.each do |document|
      out.print "%+0.2f " % document
    end
    out.print "]"
    out.puts
  end

  out.string
end