0
我試圖實現Bing Spell Check API v7。這是我目前的功能:Bing拼寫檢查API v7的實現返回0 flaggedTokens
# spell check
function bing_spell_check($q, $lang) {
$param = array();
$param['appName'] = PRO_NAME;
$param['text'] = $q;
$param['setLang'] = $lang;
$url = 'https://api.cognitive.microsoft.com/bing/v7.0/SpellCheck?'.http_build_query($param);
$process = curl_init();
curl_setopt($process, CURLOPT_URL, $url);
curl_setopt($process, CURLOPT_TIMEOUT, 10);
curl_setopt($process, CURLOPT_RETURNTRANSFER, true);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($process, CURLOPT_HTTPHEADER,
array(
'Accept: application/ld+json',
'Ocp-Apim-Subscription-Key: '.PRO_BING_KEY_SPELL
)
);
$response = curl_exec($process);
return $response;
}
的問題是,這個例子:
print_r(bing_spell_check('en', 'whts yur name?'));
返回:
{
"@context":{
"@vocab":"http:\/\/bingapis.com\/v7\/schemas\/",
"s":"http:\/\/schema.org\/",
"@base":"https:\/\/api.cognitive.microsoft.com\/api\/v7\/"
},
"@type":"SpellCheck",
"flaggedTokens":[
]
}
這意味着它沒有發現任何錯誤。我跑了同樣的試驗Bing's test tool,我收到這個結構,而不是:
{
"_type": "SpellCheck",
"FlaggedTokens": [
{
"Offset": 0,
"Token": "whts",
"Type": "UnknownToken",
"Suggestions": [
{
"suggestion": "what's",
"Score": 0.909352914464075
},
{
"suggestion": "whats",
"Score": 0.810588859407343
},
{
"suggestion": "what is",
"Score": 0.680176771139565
}
]
},
{
"Offset": 5,
"Token": "yur",
"Type": "UnknownToken",
"Suggestions": [
{
"suggestion": "your",
"Score": 0.909352914464075
}
]
}
]
}
我失去了一些東西。有任何想法嗎?謝謝!
不能相信我沒有注意到這樣一個愚蠢的錯誤。這可能是凌晨3點編程的結果。立即接受答案。謝謝! – andufo
@andufo沒問題!我很高興能夠幫助你。 –