gpt4 book ai didi

c# - 谷歌拼写检查器 API

转载 作者:行者123 更新时间:2023-11-30 17:09:53 24 4
gpt4 key购买 nike

有人知道吗?我通过了拼写检查“accelerants”,这是一个非常好的词。我回来“加速”?当我在浏览器中打开 Google 并输入“accelerants”时,它没有提示“accelerates”?

using System;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;

namespace SpellCheck
{
class googel_SP
{
public string word;
public void run_G()
{
string retValue = string.Empty;
string Iword = "accelerants";

try
{
string uri = "https://www.google.com/tbproxy/spell?lang=en:";
using (WebClient webclient = new WebClient())
{
string postData = string.Format("<?xml version=\"1.0\" encoding=\"utf-8\" ?> "
+ "<spellrequest textalreadyclipped=\"0\" ignoredups=\"0\" ignoredigits=\"1\" "
+ "ignoreallcaps=\"1\"><text>{0}</text></spellrequest>", Iword);

webclient.Headers.Add("Content-Type", "application/x-www-form- urlencoded");
byte[] bytes = Encoding.ASCII.GetBytes(postData);
byte[] response = webclient.UploadData(uri, "POST", bytes);
string data = Encoding.ASCII.GetString(response);
if (data != string.Empty)
{
retValue = Regex.Replace(data, @"<(.|\n)*?>", string.Empty).Split('\t')[0];
Console.WriteLine(" word in -> " + word + " word out -> " + retValue);
}
}
}
catch (Exception exp)
{

}
//return retValue;
}
}

}

最佳答案

有趣...我运行了您的代码,如果我故意传递“accelerants”作为搜索词,它会正确返回“accelerants”。但是,如果我通过“加速剂”,它会返回“加速”。更改语言和文本编码似乎没有什么不同。

这是将完成相同工作的替代代码..显然需要一些错误处理,但你明白了:)

string retValue = string.Empty;
word = "accelerants";

string uri = string.Format( "http://www.google.com/complete/search?output=toolbar&q={0}", word );

HttpWebRequest request = ( HttpWebRequest ) WebRequest.Create( uri );
HttpWebResponse response = ( HttpWebResponse ) request.GetResponse( );

using ( StreamReader sr = new StreamReader( response.GetResponseStream( ) ) ) {
retValue = sr.ReadToEnd( );
}

XDocument doc = XDocument.Parse( retValue );

XAttribute attr = doc.Root.Element( "CompleteSuggestion" ).Element( "suggestion" ).Attribute( "data" );

string correctedWord = attr.Value;

关于c# - 谷歌拼写检查器 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12439204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com