/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static void Main(string[] args) { System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); // first break the sentence up into words, string[] words = sentence.Split(' '); // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); foreach (string word in words) { spellChecker.Check(word); } }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static async Task Main(string[] args) { System.Console.Write("Please enter a sentence: "); // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled var sentenceArray = SentenceShredder(System.Console.ReadLine()); // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(); var misspelledWords = new List <string>(); foreach (var word in sentenceArray) { if (!await spellChecker.Check(word)) { misspelledWords.Add(word); } } if (misspelledWords.Any()) { System.Console.WriteLine($"You have {misspelledWords.Count} misspelled word{(misspelledWords.Count > 1 ? "s" : string.Empty)}"); foreach (var badWord in misspelledWords) { System.Console.WriteLine($"{badWord}"); } } System.Console.Read(); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static void Main(string[] args) { System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine() ?? ""; var words = sentence.ToLower().Split(new[] { ' ', '.', ',', '!', '?', ';' }, StringSplitOptions.RemoveEmptyEntries); var distinctWords = new HashSet <string>(words).ToList(); var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); var spellChecks = distinctWords.Select(distinctWord => spellChecker.CheckAsync(distinctWord)).ToList(); Task.WaitAll(spellChecks.ToArray()); var distinctMisspelledWords = distinctWords.Where((distinctWord, index) => !spellChecks[index].Result).ToList(); if (distinctMisspelledWords.Any()) { var misspelledWords = string.Join(" ", distinctMisspelledWords); System.Console.WriteLine($"Misspelled words: {misspelledWords}"); } else { System.Console.WriteLine("There were no misspelled words!"); } System.Console.ReadLine(); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static void Main(string[] args) { System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); // first break the sentence up into words, - Parse by blank space string[] sentenceWords = sentence.Split(' '); ; // then iterate through the list of words using the spell checker - loop through string array checking each distinct word, output miss spelled words System.Console.Write("Miss Spelled Words: "); foreach (string word2Check in sentenceWords.Distinct()) { bool spelledRight = spellChecker.Check(word2Check); if (spelledRight == false) { // capturing distinct words that are misspelled System.Console.Write(word2Check + " "); } } }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static void Main(string[] args) { System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); string[] wordsArray = sentence.ToLower().Split(' ', '.', ',', '?', '!'); List <string> wordsMisspelled = new List <string>(); // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); foreach (string word in wordsArray) { if (!spellChecker.Check(word) && !wordsMisspelled.Contains(word)) { wordsMisspelled.Add(word); } } foreach (string word in wordsMisspelled) { System.Console.WriteLine($"You misspelled: {word}"); } }
public async Task <string> GetMisspelledWords(string sentence) { // Remove punctuation. If we were accepting entire documents // instead of single sentences, we might want to use // something else. var regex = new Regex(@"[\p{P}]"); var cleanedSentence = regex.Replace(sentence, ""); // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); var words = cleanedSentence.Split(new string[] { " " }, System.StringSplitOptions.RemoveEmptyEntries).Distinct(); var wordTasks = new List <WordTask>(); foreach (var word in words) { wordTasks.Add(new WordTask(word)); } await Task.WhenAll(wordTasks.Select(async word => { word.Result = (await spellChecker.Check(word.Word)); })); return(string.Join(" ", wordTasks.Where(t => !t.Result).Select(t => t.Word))); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static async Task Main(string[] args) { System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); System.Console.Write("Misspelled words: "); foreach (var word in sentence?.Split(' ').Select(x => x).Distinct()) { if (await spellChecker.Check(new string(word .Where(x => !char.IsPunctuation(x)) .ToArray())) == false) { System.Console.Write(word + " "); } } System.Console.ReadKey(); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static void Main(string[] args) { System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); var resultsList = new List <string>(); // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled var words = sentence.Split(' '); // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); foreach (var item in words) { if (spellChecker.Check(Regex.Replace(item, @"\p{P}", "")) == false) { resultsList.Add(Regex.Replace(item, @"\p{P}", "")); } } //returns new list without duplicate entries var noDupList = resultsList.Distinct().ToList(); System.Console.Write("Misspelled words: "); noDupList.ForEach(i => System.Console.Write("{0} ", i)); System.Console.Read(); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static void Main(string[] args) { System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); var misspelledWords = new List <string>(); string[] words = sentence.Split(' '); var MnemonicServiceProvider = new ServiceCollection() .AddScoped <ISpellChecker, MnemonicSpellCheckerIBeforeE>() .BuildServiceProvider(); var DictionaryServiceProvider = new ServiceCollection() .AddScoped <ISpellChecker, DictionaryDotComSpellChecker>() .BuildServiceProvider(); var spellChecker = new Core.SpellChecker(new ISpellChecker[] { MnemonicServiceProvider.GetService <ISpellChecker>(), DictionaryServiceProvider.GetService <ISpellChecker>() //new MnemonicSpellCheckerIBeforeE(), //new DictionaryDotComSpellChecker(), }); foreach (string word in words) { var sb = new StringBuilder(); foreach (var c in word.Where(c => char.IsLetter(c)).Select(c => c)) { sb.Append(c); } var strippedWord = sb.ToString(); System.Console.WriteLine("CHECKING \"{0}\"", strippedWord); if (!spellChecker.Check(strippedWord).Result&& !misspelledWords.Contains(strippedWord)) { misspelledWords.Add(strippedWord); } } if (misspelledWords.Count == 0) { System.Console.Write("NO SPELLING MISTAKES FOUND."); } else { System.Console.Write("WORDS WITH SPELLING MISTAKES: "); foreach (var misspelledWord in misspelledWords) { System.Console.Write("{0} ", misspelledWord); } } System.Console.ReadLine(); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static async Task Main(string[] args) { var sentence = ""; while (sentence != ":q") { System.Console.WriteLine("Please enter a sentence: "); sentence = System.Console.ReadLine(); if (string.IsNullOrWhiteSpace(sentence)) { System.Console.WriteLine("Umm I need a sentence..."); continue; } // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled var distinctWords = sentence.Split(' ').ToArray().Where(w => !string.IsNullOrWhiteSpace(w)).Distinct(); // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); var mispelledWords = new List <string>(); foreach (var word in distinctWords) { if (await spellChecker.Check(word) == false) { mispelledWords.Add(word); } } if (mispelledWords.Count > 0) { System.Console.WriteLine("For shame! Mispelled words: "); foreach (var word in mispelledWords) { System.Console.WriteLine(word); } } else { System.Console.WriteLine("No mispelled words! I'm impressed."); } } }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static void Main(string[] args) { IKernel kernel = new StandardKernel(new SpellCheckerModule()); var dictspellChecker = kernel.Get <ISpellChecker>("Dictionary"); var iespellchecker = kernel.Get <ISpellChecker>("IBeforeE"); var incorrectwords = new List <string>(); System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); var words = sentence.Split(new char[] { ' ' }); // first break the sentence up into words, foreach (var word in words) { // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { iespellchecker, dictspellChecker, }); var boolresult = spellChecker.Check(word); // then iterate through the list of words using the spell checker if (!boolresult.Result) { // capturing distinct words that are misspelled incorrectwords.Add(word); } } if (incorrectwords.Any()) { System.Console.Write("Misspelled words: "); foreach (var ic in incorrectwords.Distinct()) { System.Console.Write($"{ic} "); } System.Console.WriteLine(); } System.Console.WriteLine(); System.Console.WriteLine("Done Press Enter Key to continue"); System.Console.ReadLine(); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static async System.Threading.Tasks.Task Main(string[] args) { Print("Please enter a sentence: "); var sentence = System.Console.ReadLine(); // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); Print(""); Print("Checking spelling...Please wait."); Print(""); //Make a list of tasks to run through. var tasks = new List <Task <string> >(); //distinct & lower so we don't have to look at the same word twice. foreach (string word in sentence.ToLower().Split(' ').Distinct()) { tasks.Add(RunCheck(TrimPunctuation(word), spellChecker)); } //Get all the words that failed. var badWords = (await Task.WhenAll(tasks).ConfigureAwait(false)).Where(s => !string.IsNullOrEmpty(s)).Distinct().ToList(); Print(""); Print(""); if (badWords.Count > 0) { //Print out the list. //Let the user know they did BAD. PrintInvalidMessage(badWords); } else { //Let the user know they did good. PrintSuccessMessage(); } Print(""); Print("Press any key to exit."); System.Console.ReadKey(); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static void Main(string[] args) { System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); List <string> misspelledWords = new List <string>(); foreach (var word in sentence.Split(' ')) { if (!spellChecker.Check(word).Result&& !misspelledWords.Contains(word)) { misspelledWords.Add(word); } } if (misspelledWords.Count < 1) { System.Console.WriteLine("No incorrectly spelled words detetcted"); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadLine(); return; } var words = string.Join(" ", misspelledWords); System.Console.WriteLine(string.Format("Misspelled words: {0}", words)); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadLine(); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static async Task Main(string[] args) { System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); // LSotelo: Create a regular expression to remove punctuation from the string. Any punctuation, // as in the example above, would result in incorrect misspellings (ex, "seashore." and "sea."). sentence = System.Text.RegularExpressions.Regex.Replace(sentence, @"[^\w\s]", ""); // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled string[] words = sentence.Split(); string badWords = null; // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); // Loop through the array and check each individual word. for (int x = 0; x < words.GetUpperBound(0) + 1; x++) { if (spellChecker.Check(words[x]).Result == false) { // Duplication check. If the word already exists in the "bad" words string, ignore it. if (badWords.IndexOf(words[x]) != 0) { badWords += words[x] + " "; } } } if (badWords != "") { System.Console.WriteLine(badWords); } }
public static void Main(string[] args) { System.Console.Write("Please enter a sentance: "); var sentence = System.Console.ReadLine(); // first break the sentance up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); List <string> misspells = new List <string>(); string[] words = sentence.Split(' '); for (int i = 0; i < words.Length; i++) { string word = words[i]; word = stripPunctuation(word); if (!spellChecker.Check(word)) { if (misspells.IndexOf(word) < 0) { misspells.Add(word); } } } System.Console.WriteLine("Misspelled words:"); foreach (string mispelledWord in misspells) { System.Console.WriteLine(mispelledWord); } System.Console.ReadLine(); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static async Task Main(string[] args) { //var serviceProvider = ConfigureServiceProvider(); System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled var words = ParseSentence(sentence); // use this spellChecker to evaluate the words var spellChecker = new Core.SpellChecker(new ISpellChecker[] { new MnemonicSpellCheckerIBeforeE(), new DictionaryDotComSpellChecker(), }); // TODO - Fix environmental issues with resolving the DI package in .net standard //var spellChecker = serviceProvider.GetService<Core.SpellChecker>(); // Execute spell check var tasks = new List <Task <string> >(); foreach (var word in words) { tasks.Add(RunCheck(word, spellChecker)); } var misspelledWords = (await Task.WhenAll(tasks).ConfigureAwait(false)).Where(s => !string.IsNullOrEmpty(s)).Distinct().ToList(); // Print word list System.Console.WriteLine($"{PrintMisspelledWords(misspelledWords)}"); System.Console.WriteLine("Spellcheck has finished. Press any key to exit..."); System.Console.ReadLine(); }
/// <summary> /// This application is intended to allow a user enter some text (a sentence) /// and it will display a distinct list of incorrectly spelled words /// </summary> /// <param name="args"></param> public static async Task Main(string[] args) { var serviceProvider = new ServiceCollection() .AddLogging((options) => { options.AddConsole(); }) .AddSingleton <MnemonicSpellCheckerIBeforeE>() .AddTransient <DictionaryDotComSpellChecker>() .BuildServiceProvider(); System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled var words = sentence.Split(' '); System.Console.WriteLine("Select spell checker to use. [d]otcom, [m]nemonic, or press any key to use both."); var key = System.Console.ReadKey().Key; var checkersList = new System.Collections.Generic.List <ISpellChecker>(); switch (key) { case ConsoleKey.D: checkersList.Add(serviceProvider.GetService <DictionaryDotComSpellChecker>()); break; case ConsoleKey.M: checkersList.Add(serviceProvider.GetService <MnemonicSpellCheckerIBeforeE>()); break; default: checkersList.Add(serviceProvider.GetService <MnemonicSpellCheckerIBeforeE>()); checkersList.Add(serviceProvider.GetService <DictionaryDotComSpellChecker>()); break; } var spellChecker = new Core.SpellChecker(checkersList.ToArray()); var misspelledWords = new System.Collections.Generic.List <string>(); foreach (var word in words) { if (!await spellChecker.Check(word)) { if (!misspelledWords.Contains(word)) { misspelledWords.Add(word); } } } foreach (var misspelledWord in misspelledWords) { System.Console.WriteLine(misspelledWord); } }
public static async Task <string> MyProgram() { System.Console.Write("Please enter a sentence: "); var sentence = System.Console.ReadLine(); string misSpelledMsg = ""; string[] misSpelledWords = { }; int iMisspelledCount = 0; // use this spellChecker to evaluate the words using dependency injection var MnemonicSpellChecker = new SpellCheckerInstance(new MnemonicSpellCheckerIBeforeE()); var DictionaryChecker = new SpellCheckerInstance(new DictionaryDotComSpellChecker()); var spellChecker = new Core.SpellChecker(new SpellCheckerInstance[] { MnemonicSpellChecker, DictionaryChecker, }); //string separators char[] strSeparators = { ' ', ':', ',', ';' }; //splitting string into words string[] strInputWords = sentence.Split(strSeparators); // first break the sentence up into words, // then iterate through the list of words using the spell checker // capturing distinct words that are misspelled for (int i = 0; i < strInputWords.Length; i++) { if (strInputWords[i] != "") { if (!await spellChecker.Check(strInputWords[i])) { bool bContain = false; for (int icount = 0; icount < misSpelledWords.Length; icount++) { if (misSpelledWords[icount].ToLower() == strInputWords[i].ToLower()) { bContain = true; } } if (!bContain) { if (misSpelledMsg != "") { misSpelledMsg += ", "; } misSpelledMsg += strInputWords[i]; Array.Resize <string>(ref misSpelledWords, iMisspelledCount + 1); misSpelledWords[iMisspelledCount] = strInputWords[i]; iMisspelledCount++; } } } } if (misSpelledMsg != "") { System.Console.WriteLine("Misspelled words: " + misSpelledMsg); } else { System.Console.WriteLine("No misspelled words"); } System.Console.ReadLine(); return(misSpelledMsg); }