Sha256: 57b0380aab76313e6f5d8c2486a9e3bfb03c3d50687d8d1189b4203118c545b1

Contents?: true

Size: 420 Bytes

Versions: 1

Compression:

Stored size: 420 Bytes

Contents

module RSemantic
  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

1 entries across 1 versions & 1 rubygems

Version Path
rsemantic-0.3.0 lib/rsemantic/compare.rb