Wednesday, August 4, 2010

Spell Check in ruby and rails using BOSSMan

by Sandip Ransing 0 comments

Wrong English is an often problem while developing any website product as it gives bad view to website user and thus does direct impact on product. BOSSMan is a ruby gem that interacts with yahoo web service and provides a simplest way to overcome such errors.
Installation:
gem sources -a http://gems.github.com gem install jpignata-bossman Apply and get Application ID from yahoo developer network URl https://developer.apps.yahoo.com/ Make sure to note it for reference
Usage in ruby app
require 'rubygems' require 'bossman' include BOSSMan BOSSMan.application_id = "Your Application ID here"
Spelling Suggestions
text = BOSSMan::Search.spelling("gooogle") => #{"resultset_spell"=>[{"suggestion"=>"google"}], "responsecode"=>"200", "deephits"=>"1", "start"=>"0", "count"=>"1", "totalhits"=>"1"}}> text.suggestion => "google"
More sophisticated way of use -
1. Create a YML file containing list of kewords
2. Load YML file
3. Iterate YML hash to find out spell suggestions
Example: spelling.yml
1 keywords: 2 gooogle: 3 Barack Oabama: 4 Indian: 5 Latuur:
keywords = YAML.load_file('spelling.yml')['keywords'].keys puts "Correction suggested" keywords.each do |keyword| text = BOSSMan::Search.spelling(keyword) if defined? text.suggestion puts "#{keyword} => #{text.suggestion}" end end
Output
Correction suggested gooogle => google Barack Oabama => Barack Obama Latuur => Latour
Analyze suggestions manually and make neccesary corrections..

blog comments powered by Disqus

About The Author

Sandip is a ruby on rails developer based in pune and also a blogger at funonrails. Opensource contributor and working with Josh software Private Limited. for more info read Follow Sandip on Twitter for updates.

Connect With Me...

Github Projects

@sandipransing Twitter