-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
Hello,
I want to use the Bing spellcheck API to correct the customer input data. I followed the documentation while making the implementation and checked that the Hungarian language was listed on the support list. Supported languages; in this given link under the "Bing supported language codes", the Hungarian language is listed as "hu".
I made the call using the Rest API by the following code:
example_text = "hejes íras lopas eseten mi a teendom"
endpoint = 'https://api.bing.microsoft.com/v7.0/SpellCheck'
data = {'text': example_text}
params = {
'setLang': 'hu',
'mode': 'spell'
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Ocp-Apim-Subscription-Key': api_key,
}
response = requests.post(endpoint, headers=headers, params=params, data=data)
json_response = response.json()
print(json.dumps(json_response, indent=4))
The output of the call was the following, where is empty data, but the input data was incorrect; it contained misspellings, and if I put English example text in it, it runs correctly for English.
{
"_type": "SpellCheck",
"flaggedTokens": []
}
In the case of using the SDK, the same applies; here is the Python code snippet of the call:
endpoint = 'https://api.bing.microsoft.com/v7.0/SpellCheck?mkt=hu&setLang=hu&mode=spell'
client = SpellCheckClient(endpoint=endpoint, credentials=CognitiveServicesCredentials(subscription_key))
result = client.spell_checker('hejes íras')
print(result)
for flagged_token in result.flagged_tokens:
print(flagged_token)
for suggestion in flagged_token.suggestions:
print(suggestion)
The output of the suggested words that are clearly not Hungarian words listed:
{'additional_properties': {'_type': 'Spelling/FlaggedToken'}, 'offset': 0, 'token': 'hejes', 'type': 'UnknownToken', 'suggestions': [<azure.cognitiveservices.language.spellcheck.models._models_py3.SpellingTokenSuggestion object at 0x1024ceac0>], 'ping_url_suffix': None}
{'additional_properties': {'_type': 'Spelling/TokenSuggestion'}, 'suggestion': 'hanes', 'score': 0.723271218679888, 'ping_url_suffix': None}
{'additional_properties': {'_type': 'Spelling/FlaggedToken'}, 'offset': 6, 'token': 'íras', 'type': 'UnknownToken', 'suggestions': [<azure.cognitiveservices.language.spellcheck.models._models_py3.SpellingTokenSuggestion object at 0x1024ce6a0>], 'ping_url_suffix': None}
{'additional_properties': {'_type': 'Spelling/TokenSuggestion'}, 'suggestion': 'bras', 'score': 0.723271218679888, 'ping_url_suffix': None}
Any suggestions or help is highly appreciated.
Thanks!