Modified: trunk/Rakefile (2689 => 2690)
--- trunk/Rakefile 2011-09-06 15:04:05 UTC (rev 2689)
+++ trunk/Rakefile 2011-09-06 15:55:11 UTC (rev 2690)
@@ -126,3 +126,12 @@
end
end
+desc 'Update topic titles'
+task "myexp:topic:update_titles" do
+ require File.dirname(__FILE__) + '/config/environment'
+
+ Topic.find(:all).each do |topic|
+ topic.update_title
+ end
+end
+
Modified: trunk/app/models/topic.rb (2689 => 2690)
--- trunk/app/models/topic.rb 2011-09-06 15:04:05 UTC (rev 2689)
+++ trunk/app/models/topic.rb 2011-09-06 15:55:11 UTC (rev 2690)
@@ -29,4 +29,14 @@
self.attributes["name"]
end
-end
\ No newline at end of file
+ def update_title
+
+ # get tags and ensure they are sorted with the most probability first
+ tags = topic_tag_map.sort do |a, b| b.probability <=> a.probability end
+
+ # title is the first three (most probable) tags
+ title = tags[0..2].map do |ttm| ttm.tag.name end.join(" - ")
+
+ update_attribute(:name, title)
+ end
+end