public async Task <string> CheckSpellingAsync(ArticleViewModel model)
        {
            var market      = "en-US";
            var clientId    = ""; // we don't have this yet
            var geoLocation = London;
            var ipAddress   = GetPublicIpAddress();

            SpellCheckClient client = new SpellCheckClient(new ApiKeyServiceClientCredentials(Key));

            var response = await
                           client.SpellCheckerWithHttpMessagesAsync(model.Body, market : market,
                                                                    clientId : clientId, clientIp : ipAddress, location : geoLocation, mode : "spell");

            return(await response.Response.Content.ReadAsStringAsync());
        }
        internal static async Task <string> SpellCheck(this string text, string apiKey, string countryCode = "US", string market = "en-US")
        {
            if (string.IsNullOrEmpty(text))
            {
                return(text);
            }

            var client           = new SpellCheckClient(new ApiKeyServiceClientCredentials(apiKey));
            var spellCheckResult = await client.SpellCheckerAsync(text, setLang : market, market : market, countryCode : countryCode, mode : "spell");

            foreach (var flaggedToken in spellCheckResult.FlaggedTokens)
            {
                text = text.Replace(flaggedToken.Token, flaggedToken.Suggestions.FirstOrDefault().Suggestion);
            }
            return(text);
        }
        internal static async Task <string> SpellCheck(this string text, string apiKey)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(text);
            }

            var client           = new SpellCheckClient(new ServiceCredentials.ApiKeyServiceClientCredentials(apiKey));
            var spellCheckResult = await client.SpellCheckerAsync(text);

            foreach (var flaggedToken in spellCheckResult.FlaggedTokens)
            {
                text = text.Replace(flaggedToken.Token, flaggedToken.Suggestions.FirstOrDefault().Suggestion);
            }
            return(text);
        }
        public static void Main(string[] args)
        {
            string subscriptionKey = "c66350565d054032b93fdb323939d884";

            string sourceString = "james had a very good day at at work he wass so plaesed with himslf";

            SpellCheckClient client = new SpellCheckClient(new ApiKeyServiceClientCredentials(subscriptionKey));
            var spellResult         = client.SpellCheckerAsync(sourceString, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "proof", null, null).Result;

            foreach (var token in spellResult.FlaggedTokens)
            {
                Console.WriteLine(PrettyToken(token));
            }

            Console.WriteLine("Finished");
            Console.ReadKey();
        }
Ejemplo n.º 5
0
        public static string Query_SpellCheck(string querytext)
        {
            List <String> correction = new List <string>();

            var client = new SpellCheckClient(new ApiKeyServiceClientCredentials("c1a10976d73e469382f0860c0ab2dac4"));

            char[]   splits = new char[] { ' ', '\t', '\'', '"', '-', '(', ')', ',', '’', '\n', ':', ';', '?', '.', '!' }; // Set token delimiters
            string[] tokens = querytext.ToLower().Split(splits, StringSplitOptions.RemoveEmptyEntries);                    // Tokenisation

            var result = client.SpellCheckerWithHttpMessagesAsync(text: querytext.Replace("Title:", "").Replace("Author:", ""), mode: "proof", acceptLanguage: "en-US").Result;

            //Console.WriteLine("Correction for Query:" + querytext);

            // SpellCheck Results
            if (result?.Body.FlaggedTokens?.Count > 0)
            {
                foreach (var x in result.Body.FlaggedTokens)
                {
                    int index = Array.IndexOf(tokens, x.Token);

                    var suggestions = x.Suggestions;
                    if (suggestions?.Count > 0)
                    {
                        var firstSuggestion = suggestions.FirstOrDefault();
                        //Console.WriteLine(firstSuggestion.Suggestion);
                        tokens[index] = firstSuggestion.Suggestion;
                        correction.Add("\"" + x.Token + "\" has been corrected to \"" + tokens[index] + "\"");
                    }
                }
            }

            string afterQuery = "";

            foreach (string t in tokens)
            {
                afterQuery += t + " ";
            }
            //Console.WriteLine(afterQuery.TrimEnd());
            if (correction.Count > 0)
            {
                var message = string.Join(Environment.NewLine, correction);
                MessageBox.Show("Words have been corrected by the Spell Checker\n\n" + message, "Word Correction", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            return(afterQuery.TrimEnd().Replace("title", "Title:").Replace("author", "Author:"));
        }
        public async Task <SpellingResult> CheckSpellingAsync(string text, string clientId = "")
        {
            string Key         = _configuration["BingSpellCheckKey"];
            var    geoLocation = Istanbul;
            var    ipAddress   = GetPublicIpAddress();

            SpellCheckClient client = new SpellCheckClient(new ApiKeyServiceClientCredentials(Key));
            var response            = await client.SpellCheckerWithHttpMessagesAsync(text, market : Market, clientId : clientId, clientIp : ipAddress, location : geoLocation, mode : Mode);

            HttpResponseHeaders responseHeaders = response.Response.Headers;
            var spellingResult = new SpellingResult
            {
                ClientId = GetHeaderValue(responseHeaders, "X-MSEdge-ClientID"),
                TraceId  = GetHeaderValue(responseHeaders, "BingAPIs-SessionId"),
                Text     = ProcessResults(text, response.Body.FlaggedTokens)
            };

            return(spellingResult);
        }
        public async Task <SpellingResult> CheckSpellingAsync(string text, string clientId = "")
        {
            var market      = "en-GB";
            var geoLocation = London;
            var ipAddress   = GetPublicIpAddress();

            SpellCheckClient client = new SpellCheckClient(new ApiKeyServiceClientCredentials(Key));

            var response = await
                           client.SpellCheckerWithHttpMessagesAsync(text, market : market,
                                                                    clientId : clientId, clientIp : ipAddress, location : geoLocation);

            var spellingResult = new SpellingResult
            {
                ClientId = GetHeaderValue(response.Response.Headers, "X-MSEdge-ClientID"),
                TraceId  = GetHeaderValue(response.Response.Headers, "BingAPIs-SessionId"),
                Text     = ProcessResults(text, response.Body.FlaggedTokens)
            };

            return(spellingResult);
        }
Ejemplo n.º 8
0
        private async Task <string> SpellCheckAsync(string inputText)
        {
            var client = new SpellCheckClient(new ApiKeyServiceClientCredentials(ConfigurationManager.AppSettings["BingSpellCheckKey"]));

            //var response = await client.SpellCheckerWithHttpMessagesAsync(inputText);

            /*
             * For SpellCheck mode, The default is Proof. 1) Proof—Finds most spelling and grammar mistakes.
             * 2) Spell—Finds most spelling mistakes but does not find some of the grammar errors that Proof
             * catches (for example, capitalization and repeated words). Possible values
             * include: 'proof', 'spell'
             * Ref SDK - https://github.com/Azure/azure-sdk-for-net/blob/psSdkJson6/src/SDKs/CognitiveServices/dataPlane/Language/SpellCheck/BingSpellCheck/Generated/SpellCheckClient.cs
             * */
            var response = await client.SpellCheckerWithHttpMessagesAsync(text : inputText,
                                                                          mode : "spell", acceptLanguage : "en-US");

            //Get the service task result
            var result = response.Response;

            var spellcheckContent = await result.Content.ReadAsStringAsync();

            return(spellcheckContent);
        }
        public static async Task checkSpelling(SpellCheckClient client, string query)
        {
            var result = await client.SpellCheckerAsync(text : query, mode : "proof");

            Console.WriteLine("Original query: \n" + query);
            Console.WriteLine();
            Console.WriteLine("Misspelled words:");
            foreach (SpellingFlaggedToken token in result.FlaggedTokens)
            {
                Console.WriteLine(token.Token);
            }

            Console.WriteLine();
            Console.WriteLine("Suggested corrections:");
            foreach (SpellingFlaggedToken token in result.FlaggedTokens)
            {
                foreach (SpellingTokenSuggestion suggestion in token.Suggestions)
                {
                    // Confidence values range from 0 (none) to 1.0 (full confidence)
                    Console.WriteLine(suggestion.Suggestion + " with confidence " + Math.Round((decimal)suggestion.Score, 2));
                }
            }
        }
Ejemplo n.º 10
0
        public MortalBotService(IConfiguration _config)
        {
            //////////////////////////////////////////// AZURE SPEEL CHECK

            apiKey      = _config.GetSection(sectionConfig).GetValue <string>("ApiKey");
            countryCode = _config.GetSection(sectionConfig).GetValue <string>("CountryCode");
            market      = _config.GetSection(sectionConfig).GetValue <string>("Market");
            mode        = _config.GetSection(sectionConfig).GetValue <string>("Mode");



            ApiKeyServiceClientCredentials _credentials = new ApiKeyServiceClientCredentials(apiKey);

            _spellCheckClient = new SpellCheckClient(_credentials);


            //////////////////////////////////////////// AZURE SEARCH


            searchServiceName  = _config.GetSection("AzureSearchConnection").GetSection("SearchServiceName").Value;
            queryApiKey        = _config.GetSection("AzureSearchConnection").GetSection("SearchServiceQueryApiKey").Value;
            searchServiceIndex = _config.GetSection("AzureSearchConnection").GetSection("SearchServiceIndex").Value;
            indexClient        = new SearchIndexClient(searchServiceName, searchServiceIndex, new SearchCredentials(queryApiKey));
        }
Ejemplo n.º 11
0
 public SpellCheckService()
 {
     spellCheckClient = new SpellCheckClient(new ApiKeyServiceClientCredentials("5363528dc54e4611a206afcf2dcad502"));
 }