lib/semantic/compare.rb in rsemantic-0.1.3 vs lib/semantic/compare.rb in rsemantic-0.1.4
- old
+ new
@@ -7,10 +7,13 @@
cosine(vector1, vector2)
end
def cosine(vector1, vector2)
unless vector2.nil? or vector1.nil?
- (vector2.dot(vector1)) / (vector1.norm * vector2.norm)
+ v1 = vector1.row
+ v2 = vector2
+ score = (v1 * v2) / (vector1.norm * vector2.norm)
+ score.nan? ? 0.0 : score
end
end
end