12

I want to use Google's spelling correction/suggestions in an app I'm doing. I've googled it but all I found was examples for Google's canceled SOAP API and the newly deprecated XML Web Search API.

I just want to be able to send a search query and get back the suggested correction.

alt text

Which API can I use now? Could you give an example of its usage? Is there a C# Wrapper around it?

Thanks!

EDIT:

The problem with Bing and Yahoo's spelling API is that they seem to check against a dictionary, so some brand/product names are not recognized, Googles seem to be based on usual spelling mistakes and pages they ended up visiting, so it can suggest spell checking for the most common things, ie:

if you type

"hello word"

it will say

"do you mean hello world?"

even though it is spelled correctly

Francisco Noriega
  • 13,725
  • 11
  • 47
  • 72
  • possible duplicate of [How does the Google "Did you mean?" Algorithm work?](http://stackoverflow.com/questions/307291/how-does-the-google-did-you-mean-algorithm-work) – dav_i Aug 13 '14 at 15:23

6 Answers6

10

If you don't have to use Google, the Bing API actually includes Spelling, you can use http://bingsharp.codeplex.com/

Homde
  • 4,246
  • 4
  • 34
  • 50
  • No, I dont have to use it, I'm also experimenting with yahoos YQL, its just that Google's would be the most known one, thanks for this one! – Francisco Noriega Nov 21 '10 at 21:22
6

If anything, you could build it yourself with a small C# program that downloaded google's search page for a particular word i.e http://www.google.com/search?q=filipines and search for the

Showing results for philippines. Search instead for filipines

fragment, which would be contained in a <p class="sp_cnt"> in case the wording was incorrect, from there you could just extract the suggested correct spelling

Update: Actually, depending on a couple of things, it could also be in a <p class="ssp">, I think it depends on how long the phrase is, anyways you could search for the <span id="topstuff"> and find a child paragraph with either class, and extract the correct spelling from there, note that in the "ssp" case the wording is different:

Did you mean: showing result for phi

You could parse the page as an XML, if the code is XHTML compliant, then hurrah, otherwise you would have to tweak it a bit, making it "well-formed" to be loaded with XML as a XMLDocument. After that it should be easy finding the fragment of the page (should it exist) that tells you the appropriate spelling

bevacqua
  • 47,502
  • 56
  • 171
  • 285
  • 1
    Yeah, I've been thinking of crawling the page as well, but I want to leave that as the last mean to do it, I'd much rather prefer an Official API that might not break from one day to the other.. actually im looking at Yahoo's YQL too, its pretty good! – Francisco Noriega Nov 21 '10 at 16:59
  • 2
    If you call web search too often, a captcha might popup once in a while and you could also be blocked. Better use an API (which usually has daily limit unless you pay). – Martin Konicek Nov 21 '10 at 22:24
  • Even though this is not the "right" way, its the only way I've found. Google search suggestions and related searches are just way better than bing's and yahoo's... so I guess I'll roll with this until something better comes out – Francisco Noriega Nov 23 '10 at 17:12
2

There is a Google-API Spelling implementation in Java, implemented by Kamran. It is not that complicated as I looked into the source. You might consider translating it into C# ?!

The project page states that

This is a simple Java API that makes it very easy to call Google's spell checker service from Java applications.

but which google spell checker service it uses I don't know, but it works pretty good.

matthaeus
  • 797
  • 2
  • 7
  • 17
2

Here is a list of all google APIs: http://code.google.com/apis/ajax/playground/

Unfortunately it seems that there is no spelling API.

Martin Konicek
  • 39,126
  • 20
  • 90
  • 98
2

Somewhat late, but Google's spelling checker is part of the Search API. See

http://code.google.com/apis/soapsearch/reference.html#1_3

Jerry
  • 394
  • 2
  • 8
  • "Spelling requests submit a query to the Google SOAP Search API service"... as I said in the question the SOAP API has been dismissed and the XML one has been deprecated as of november... , still, thanks for the effort :) – Francisco Noriega Dec 16 '10 at 08:13
2

Google Search Api Sample Code http://deepumi.wordpress.com/2010/05/20/google-spell-checker-api-asp-net-c/ As u will use Proxy Authentication Error will come then add following line of code to remove error System.Net.IWebProxy theProxy = webclient.Proxy; if (theProxy != null) theProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;