Mark Watson’s Artificial Intelligence Books and Blog

Share this post

Ruby client for search and spelling correction using Bing's APIs

markwatson.com

Ruby client for search and spelling correction using Bing's APIs

Mark Watson
Jun 8, 2009
Share
Share this post

Ruby client for search and spelling correction using Bing's APIs

markwatson.com

I noticed that Microsoft allows free use of their search and spelling correction APIs. I just played with the APIs for a few minutes. Here is a Ruby code snippet that I just wrote:

API_KEY = ENV['BING_API_KEY']

require 'rubygems' # needed for Ruby 1.8.x
require 'simple_http'
require 'json'

def search query
  uri = "http://api.search.live.net/json.aspx?AppId=#{API_KEY}&Market=en-US&Query=#{CGI.escape(query)}&Sources=web+spell&Web.Count=4"
  JSON.parse(SimpleHttp.get(uri))["SearchResponse"]["Web"]["Results"]
end

def correct_spelling text
  uri = "http://api.search.live.net/json.aspx?AppId=#{API_KEY}&Market=en-US&Query=#{CGI.escape(text)}&Sources=web+spell&Web.Count=1"
  JSON.parse(SimpleHttp.get(uri))["SearchResponse"]["Spell"]["Results"][0]["Value"]
end

You need a free Bing API key - notice that I set the key value in my environment. If you get a key, then try:

search "semantic web java ruby lisp"
correct_spelling "semaantic web jaava ruby lisp"

The first method does spelling correction before search.

Share
Share this post

Ruby client for search and spelling correction using Bing's APIs

markwatson.com
Comments
Top
New

No posts

Ready for more?

© 2023 Mark Watson
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing