The Shortest Spell Checker
Recently I fell in love. With Ruby, a programming language. It has all the features I have been looking for since I started to learn programming. It has an elegant yet powerful syntax, a number of APIs and… is as simple as possible, but not simpler.
Yesterday I discovered Google SOAP Search API. Without any hesitation I decided to write a simple spell checker based on Google API. Of course, in Ruby. The script is only four lines long:
require 'soap/rpc/driver'
stub = SOAP::RPC::Driver.new("http://api.google.com/search/beta2", "urn:GoogleSearch")
stub.add_method('doSpellingSuggestion', 'key', 'phrase')
puts stub.doSpellingSuggestion(ENV['GOOGLE_KEY'], ARGV[0])
It assumes that in the $GOOGLE_KEY environment variable your Google key is stored. Additionally, the first program argument is used as a word (or a sentence) that is to be checked. Certainly, the script is too stupid to be really useful. But I think that it demonstrates Ruby’s power quite well.
But how fast it runs? hahaha
↓ Quote | Posted 27 June, 2006, 8:05