Author Sur
License MIT
Homepage http://expressica.com/auto_tags
Mailing List auto_tags@googlegroups.com


Introduction

AutoTags, an open source project, is a plugin for RubyOnRails applications to automatically generate the relevant tags for the provided content by making use of the Yahoo term extraction api. Its quite simple to use and provide easy integration with ActiveRecord. The plugin is very useful for social applications, community websites and all those networking applications where there is a scope of user generate content to be tagged. No more heck for the admin to sit and add the tags to the content or waiting for the users to add the tags to their content.

Installation

Install the plugin by issuing the following command from your rails application root

ruby script/plugin install http://auto-tags.googlecode.com/svn/trunk/auto_tags

Usage & Examples

The plugin is quite simple to use and provides direct integration with ActiveRecord’s model classes.
Here are the different examples for different use cases…
In our model classes you just need to specify the method names that should be called to gather the content out of which you need to generate the tags.

NOTE: Yahoo restricts the api usage for 5000 requests in 24 hours from a single IP. So, if your requests goes beyond that, you will get an empty array.

Example including single attribute

class Vendor < ActiveRecord::Base
  auto_tags :include => :product
end

Example including multiple attributes

class Vendor < ActiveRecord::Base
  auto_tags :include => [:product, :description]
end

Example including associated attributes

class Vendor < ActiveRecord::Base
  has_many :books
  auto_tags :include => [:product, :description, :books_names]

  def books_names
    books.collect{|b| b.name}.join(’ ‘)
  end
end

Now, after adding the directive auto_tags as explained above… you will get a method with the model’s object to fetch the relevant tags automatically as…

@vendor.get_auto_tags

Integrating with acts_as_taggable

The method get_auto_tags returns the array of relevant tags based upon the content provided through the model.
This can further be used with the acts_as_taggable simply like this…

@vendor.tag_list.add(@vendor.get_auto_tags)

which can also be automated within the model using the before save callback as…

Example automating with callback

class Vendor < ActiveRecord::Base
  acts_as_taggable
  has_many :books
  auto_tags :include => [:product, :description, :books_names]

  def books_names
    books.collect{|b| b.name}.join(’ ‘)
  end

  protected
  def before_save
    self.tag_list.add(self.get_auto_tags)
  end
end

which will automatically updates the tags if the user adds new data.

Recommend

If you liked the plugin then please recommend me on workingwithrails.

Any issue/comment are welcome on the mailing list auto_tags@googlegroups.com.

4 Comments to "Auto Tags"

  • Andreas Roedl said:

    Found a little bug in the readme:

    AutoTags::AutoTagsGenerator.generate_tags(content)

    should be:

    AutoTags::AutoTagsGeneration.generate_tags(content)

  • sur said:

    Hi Andreas,

    Thanks for pointing that out.
    Fixed!

  • Jörg Battermann said:

    It’s also worth mentioning that this code (as all the other ones floating around) based on YTE are only working properly with English text. Other languages are not supported. There are other services out there that do that, but Yahoo! is English-only. Everything else ends up being gibberishy tags.

    -J

  • sur said:

    Hi Jörg,

    Thanks for pointing that out.
    Might be you are right, I have only tried it for English Language.

Please share your thoughts