如何在代码中提到的文本上使用 bing 拼写检查 API 的拼写检查功能?

How can i use spell check feature of bing spell check API on the text mentioned in the code?

提问人:iced 提问时间:11/15/2023 更新时间:11/15/2023 访问量:12

问:

我正在使用此代码检查任何语法或拼写检查,但似乎代码不起作用。请在下面的代码中为我提供一些更改以获得预期的输出

import http.client, json, urllib, urllib.request, urllib.error, urllib.parse

key = '82255asf52f45f499eb23509d00789a'
header = {
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': key
}
baseUrl = "api.bing.microsoft.com"

**text = 'my name are sam'**

params = urllib.parse.urlencode({
    'text': text,
    'mkt': 'en-US',
    'setLang': 'EN',
    'postContextText': '',
    'preContextText': ''
})
endpoint = '/v7.0/spellcheck?%s' % params
body = {}
try:
    conn = http.client.HTTPSConnection(baseUrl)
    conn.request('POST', endpoint, body, header)
    response = conn.getresponse()
    jsonData = response.read().decode('UTF-8')
    data = json.loads(jsonData)
    if data['flaggedTokens'] == []:
        print('No Suggestion ')
    for token in data['flaggedTokens']:
        print('You can replace ' + token['token'] + ' with folowing words')
        for suggestion in token['suggestions']:
            print(suggestion['suggestion'] + " Score is " + str(suggestion['score']))
    conn.close()
except Exception as ex:
    print(ex)

电流输出:无建议

预期输出:我的名字是 sam

python 拼写检查 必应 bing-api

评论


答: 暂无答案