more work

This commit is contained in:
albert
2010-10-19 19:34:31 -04:00
parent cb3d7e9e9b
commit acdce69f20
48 changed files with 2494 additions and 1585 deletions

View File

@@ -1,23 +1,27 @@
class RelatedTagCalculator
def find_tags(tag, limit)
def self.find_tags(tag, limit)
Post.find_by_tags(tag, :limit => limit, :select => "posts.tag_string", :order => "posts.md5").map(&:tag_string)
end
def calculate_from_sample(name, limit, category_constraint = nil)
def self.calculate_from_sample_to_array(tags, category_constraint = nil)
convert_hash_to_array(calculate_from_sample(tags, Danbooru.config.post_sample_size, category_constraint))
end
def self.calculate_from_sample(tags, limit, category_constraint = nil)
counts = Hash.new {|h, k| h[k] = 0}
case category_constraint
when Tag.categories.artist
limit *= 5
limit *= 4
when Tag.categories.copyright
limit *= 4
limit *= 3
when Tag.categories.character
limit *= 3
limit *= 2
end
find_tags(name, limit).each do |tags|
find_tags(tags, limit).each do |tags|
tag_array = Tag.scan_tags(tags)
if category_constraint
tag_array.each do |tag|
@@ -36,11 +40,11 @@ class RelatedTagCalculator
counts
end
def convert_hash_to_array(hash)
def self.convert_hash_to_array(hash)
hash.to_a.sort_by {|x| -x[1]}.slice(0, 25)
end
def convert_hash_to_string(hash)
def self.convert_hash_to_string(hash)
convert_hash_to_array(hash).flatten.join(" ")
end
end