Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: zenkalia/dank
base: 654f32ab72
...
head fork: zenkalia/dank
compare: 5d7aba3a2f
  • 1 commit
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Sep 11, 2012
Mike Kendall :game_die: adding tag_suggestions, tag_suggestions_hash and some really shitty…
… specs for covering them
5d7aba3
Showing with 34 additions and 0 deletions.
  1. +2 −0  README.md
  2. +28 −0 lib/dank/mixin.rb
  3. +4 −0 spec/dank_spec.rb
2  README.md
View
@@ -55,6 +55,8 @@ If you'd like to compare yourself to someone else by a distance rather than an a
To get the distance between two tags, try `User.tag_distance 'sexy', 'beast'`.
+If you want tag suggestions for a taggable based on what tags is already has, use `a.tag_suggestions` or `a.tag_suggestions_hash`.
+
## Config!
`Dank.config` takes a hash. Options currently are:
28 lib/dank/mixin.rb
View
@@ -44,6 +44,26 @@ def get_hash
Hash[redis.zrange("dank:#{Dank.app_name}:#{@taggable_name}:#{@objekt.id}",0,-1,{withscores:true})]
end
+ def tag_suggestions_hash
+ weights = {}
+ self.get_hash.each do |k,v|
+ self.class.tag_neighbors_hash(@taggable_name, @tag_name, k).each do |k2,v2|
+ unless self.get_array.index k2
+ weights[k2] ||= 0
+ weights[k2] += v*v2
+ end
+ end
+ end
+ weights
+ end
+
+ def tag_suggestions
+ weights = tag_suggestions_hash
+ weights.keys.sort do |a,b|
+ self.class.sort_weights weights[a], weights[b]
+ end
+ end
+
def reorder(tags)
return false unless @objekt.id
return false unless tags.sort == get_array.sort # for making sure that we don't allow a reorder without every tag present
@@ -190,6 +210,14 @@ def tag_name(name)
tag_lib.reorder(tags)
end
+ define_method :"#{name}_suggestions" do
+ tag_lib.tag_suggestions
+ end
+
+ define_method :"#{name}_suggestions_hash" do
+ tag_lib.tag_suggestions_hash
+ end
+
define_method :"shared_#{name}s" do |other|
other_id = other.respond_to?(:id) ? other.id : other
tag_lib.get_shared other_id
4 spec/dank_spec.rb
View
@@ -114,6 +114,10 @@ def id
other_user.add_genre 'pop'
other_user.remove_genre 'rap'
klass.genre_neighbors('pop').should == []
+ user.remove_genre 'rap'
+ user.genre_suggestions.should == ['rap']
+ user.remove_genre 'country'
+ user.genre_suggestions.should =~ ['rap', 'country']
end
end
end

No commit comments for this range

Something went wrong with that request. Please try again.