Skip to content

Commit 3877d02

Browse files
authored
Initial commit
1 parent e07171a commit 3877d02

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from azure.cognitiveservices.language.spellcheck import SpellCheckAPI
2+
from msrest.authentication import CognitiveServicesCredentials
3+
4+
import os
5+
6+
'''
7+
This Bing Spell Check quickstart checks some misspelled words and suggests corrections.
8+
9+
Prerequisites:
10+
- Add your Bing Spell Check subscription key to your environment variables, using
11+
BING_SPELL_CHECK_SUBSCRIPTION_KEY as a variable name.
12+
- Install the following modules:
13+
pip install azure.cognitiveservices.language.spellcheck
14+
pip install msrest
15+
16+
Python SDK: https://docs.microsoft.com/en-us/python/api/overview/azure/cognitiveservices/spellcheck?view=azure-python
17+
'''
18+
19+
# Add your Bing Spell Check subscription key to your environment variables.
20+
SUBSCRIPTION_KEY = os.environ['BING_SPELL_CHECK_SUBSCRIPTION_KEY']
21+
22+
# Create a client
23+
client = SpellCheckAPI(CognitiveServicesCredentials(SUBSCRIPTION_KEY))
24+
25+
try:
26+
# Original query
27+
query = 'bill gtaes was ehre toody'
28+
29+
# Check the query for misspellings
30+
result = client.spell_checker(query, mode='proof') # mode can be 'proof' or 'spell'
31+
32+
# Print the suggested corrections
33+
for token in result.flagged_tokens:
34+
for suggestion_object in token.suggestions:
35+
print(suggestion_object.suggestion)
36+
37+
except Exception as err:
38+
print("Encountered exception. {}".format(err))

0 commit comments

Comments
 (0)