Ruby-Tf-Idf
This gem calculates TF-IDF to find the most relevant words of each document in corpus
TF-IDF is for Term Frequency - Inverse Document Frequency http://en.wikipedia.org/wiki/Tf%E2%80%93idf
Installation
Add this line to your application's Gemfile:
gem 'ruby-tf-idf'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install ruby-tf-idf
Usage
require 'rubygems'
require 'ruby-tf-idf'
corpus =
[
'A big enough hammer can usually fix anything',
'A bird in the hand is a big mistake .',
'A bird in the hand is better than one overhead!',
'A career is a job that takes about 20 more hours a week.'
'A clean desk is a sign of a cluttered desk drawer.'
'A cynic smells flowers and looks for the casket.'
]
limit = 2 #restrict to the top 2 relevant words per document
exclude_stop_words = false
@t = Tfidf.new(corpus,limit,exclude_stop_words)
puts @t.tf_idf
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request