Sha256: 6583c9d8eee8a797dca6a00aa8762281d347b5081b476bac9d71a576f6198667

Contents?: true

Size: 419 Bytes

Versions: 3

Compression:

Stored size: 419 Bytes

Contents

module Semantic
  class Compare

    class << self
      
      def similarity(vector1, vector2)
        cosine(vector1, vector2)
      end
      
      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

    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rsemantic-0.2.1 lib/semantic/compare.rb
rsemantic-0.2.0 lib/semantic/compare.rb
rsemantic-0.1.4 lib/semantic/compare.rb