public static async Task <string> SpellCheck(this SpellCheckAPI api, string spellcheck) { return((await api.SpellCheckerWithHttpMessagesAsync(text: spellcheck, mode: "proof")) .Body .FlaggedTokens .Where(token => token.Suggestions.First().Score > 0.70) .Select <SpellingFlaggedToken, Func <string, string> >(token => (value => value.Replace(token.Token, token.Suggestions.First().Suggestion))) .DefaultIfEmpty(_ => _) .Aggregate((a, b) => s => a(b(s))) .Invoke(spellcheck)); }
public static void SpellCheckCorrection(string subscriptionKey) { var client = new SpellCheckAPI(new ApiKeyServiceClientCredentials(subscriptionKey)); try { var result = client.SpellCheckerWithHttpMessagesAsync(text: "Bill Gatas", mode: "proof").Result; Console.WriteLine("Correction for Query# \"bill gatas\""); // SpellCheck Results if (result?.Body.FlaggedTokens?.Count > 0) { // find the first spellcheck result var firstspellCheckResult = result.Body.FlaggedTokens.FirstOrDefault(); if (firstspellCheckResult != null) { Console.WriteLine("SpellCheck Results#{0}", result.Body.FlaggedTokens.Count); Console.WriteLine("First SpellCheck Result token: {0} ", firstspellCheckResult.Token); Console.WriteLine("First SpellCheck Result Type: {0} ", firstspellCheckResult.Type); Console.WriteLine("First SpellCheck Result Suggestion Count: {0} ", firstspellCheckResult.Suggestions.Count); var suggestions = firstspellCheckResult.Suggestions; if (suggestions?.Count > 0) { var firstSuggestion = suggestions.FirstOrDefault(); Console.WriteLine("First SpellCheck Suggestion Score: {0} ", firstSuggestion.Score); Console.WriteLine("First SpellCheck Suggestion : {0} ", firstSuggestion.Suggestion); } } else { Console.WriteLine("Couldn't get any Spell check results!"); } } else { Console.WriteLine("Didn't see any SpellCheck results.."); } } catch (Exception ex) { Console.WriteLine("Encountered exception. " + ex.Message); } }