tomtaylor (owner)

Revisions

  • f6ad3d Tue Aug 05 02:21:52 -0700 2008
  • 0d9087 Tue Aug 05 02:21:30 -0700 2008
gist: 4047 Download_button fork
public
Public Clone URL: git://gist.github.com/4047.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  def similar(n = 10)
    other_tags = Tag.find(:all, :conditions => ['tags.id != ?', self.id], :include => :bookmarks)
 
    other_tags.map do |b|
      [b, tanimoto(b.bookmarks, self.bookmarks)] # compare tag listings
    end.select do |b|
      b.last > 0 # select only those which have a tanimoto greater than 0, ie. some shared tags
    end.sort do |x,y|
      y.last <=> x.last # sort on tanimoto
    end[0..n].map(&:first) # return only 0..10 bookmarks
  end
 
  def tanimoto(a,b)
    c = a.select { |v| b.include?(v) }
    coefficient = (c.size.to_f/(a.size + b.size - c.size))
  end