public async static Task CheckSpellAsync(IDialogContext context, string key, string query) { ISpellCheckAPI client = new SpellCheckAPI(new Microsoft.Azure.CognitiveServices.SpellCheck.ApiKeyServiceClientCredentials(key)); var result = await client.SpellCheckerAsync(text : query); string suggestionText = query; foreach (var item in result.FlaggedTokens) { var firstSugestion = item.Suggestions.FirstOrDefault(); if (firstSugestion != null) { suggestionText = suggestionText.Replace(item.Token, $"**{firstSugestion.Suggestion}**"); } } if (query.Equals(suggestionText)) { await context.PostAsync("Not found any suggestions."); } else { await context.PostAsync($"Did you mean: {suggestionText}"); } }
public static void SpellCheckError(string subscriptionKey) { var client = new SpellCheckAPI(new ApiKeyServiceClientCredentials(subscriptionKey)); try { var result = client.SpellCheckerAsync(mode: "proof").Result; Console.WriteLine("Correction for Query# \"empty text field\""); } catch (Exception ex) { if (ex.GetBaseException().GetType() == typeof(Exception)) { Console.WriteLine("Encountered exception. " + ex.Message); } } }
public static async Task <string> CheckGrammarAsync(string message) { Vars.StatusMessage.Text += "\n\nMESSAGE BEFORE\n" + message; // Add your Azure spellcheck API key here var client = new SpellCheckAPI(new ApiKeyServiceClientCredentials("<API KEY>")); var result = await client.SpellCheckerAsync(text : message, mode : "proof"); if (result?.FlaggedTokens?.Count > 0) { foreach (var token in result.FlaggedTokens) { message = message.Replace(token.Token, token.Suggestions[0].Suggestion); } } Vars.StatusMessage.Text += "\n\nMESSAGE AFTER\n" + message; return(message); }