通过 C# 访问 Google 拼写/建议 API [英] Accessing Google spelling/suggestion API via C#

查看:25
本文介绍了通过 C# 访问 Google 拼写/建议 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我正在做的应用中使用 Google 的拼写更正/建议.我用谷歌搜索过,但我发现的只是谷歌取消的 SOAP API 和新弃用的 XML Web Search API 的示例.

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.

我现在可以使用哪个 API?你能举例说明它的用法吗?它周围有 C# 包装器吗?

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

谢谢!

Bing 和 Yahoo 的拼写 API 的问题在于它们似乎会检查字典,因此无法识别某些品牌/产品名称,Google 似乎基于通常的拼写错误和他们最终访问的页面,因此它可以建议对最常见的事情进行拼写检查,即:

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:

如果你输入

你好词"

它会说

你是说你好世界吗?"

即使拼写正确

推荐答案

如果有的话,你可以用一个小的 C# 程序自己构建它,该程序下载了谷歌搜索页面的特定单词,即 http://www.google.com/search?q=filipines 并搜索

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

显示菲律宾的结果.改为搜索菲律宾

fragment,它将包含在 <p class="sp_cnt"> 中,以防措辞不正确,您可以从那里提取建议的正确拼写

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

更新:实际上,取决于一些事情,它也可以在 <p class="ssp"> 中,我认为这取决于短语的长度,无论如何您可以搜索 <span id="topstuff"> 并找到具有任一类的子段落,并从中提取正确的拼写,注意在 "ssp" case 措辞不同:

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:

您的意思是:显示 phi 的结果

Did you mean: showing result for phi

您可以将页面解析为 XML,如果代码与 XHTML 兼容,那就好啦,否则您将不得不稍微调整一下,使其格式良好"以作为 XMLDocument 加载 XML.之后应该很容易找到告诉你正确拼写的页面片段(如果它存在)

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

这篇关于通过 C# 访问 Google 拼写/建议 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆