Class: RSemantic::Compare

Inherits:
Object
  • Object
show all
Defined in:
lib/rsemantic/compare.rb

Class Method Summary collapse

Class Method Details

.cosine(vector1, vector2) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/rsemantic/compare.rb', line 10

def cosine(vector1, vector2)
  unless vector2.nil? or vector1.nil?
    v1 = vector1.row
    v2 = vector2
    score =  (v1 * v2) / (vector1.norm * vector2.norm)
    score.nan? ?  0.0 : score
  end
end

.similarity(vector1, vector2) ⇒ Object



6
7
8
# File 'lib/rsemantic/compare.rb', line 6

def similarity(vector1, vector2)
  cosine(vector1, vector2)
end