예제 #1
0
        /// <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>
        static void Main(string[] args)
        {
            Console.Write("Please enter a sentence: ");
            var sentence = Console.ReadLine();

            initiateSSLConfiguration();

            // 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 SpellChecker.Core.SpellChecker
                               (
                new ISpellChecker[]
            {
                new MnemonicSpellCheckerIBeforeE(),
                new DictionaryDotComSpellChecker(new HttpHandler(), getDictionaryUri()),
            }
                               );

            var words = Regex.Replace(sentence, @"[ ](?=[ ])|[^-_,A-Za-z0-9 ]+", "") //remove special characters & numbers
                        .Split(' ')                                                  //sentence to words
                        .Distinct();                                                 //remove duplicates

            var mistakes = words.Where(x => !spellChecker.Check(x));

            if (mistakes.Count() > 0)
            {
                Console.Write("Misspelled words: ");
                Console.WriteLine(string.Join(" ", mistakes.Select(x => x)));
            }
            Console.ReadLine();
        }
예제 #2
0
        /// <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>
        static void Main(string[] args)
        {
            Console.Write("Please enter a sentence: ");
            var sentence = 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 SpellChecker.Core.SpellChecker
                               (
                new ISpellChecker[]
            {
                new MnemonicSpellCheckerIBeforeE(),
                new DictionaryDotComSpellChecker(),
            }
                               );

            var words      = new string(sentence.ToCharArray().Where(c => !char.IsPunctuation(c)).ToArray()).Split(' ');
            var misspelled = words.Where(word => !spellChecker.Check(word)).Distinct().ToList();

            if (!misspelled.Any())
            {
                return;
            }
            Console.WriteLine("Misspelled words: " + string.Join(", ", misspelled));

            Environment.Exit(misspelled.Count);
        }
예제 #3
0
        /// <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>
        static void Main(string[] args)
        {
            // use this spellChecker to evaluate the words
            var spellChecker = new SpellChecker.Core.SpellChecker
                               (
                new ISpellChecker[]
            {
                new MnemonicSpellCheckerIBeforeE(),
                new DictionaryDotComSpellChecker(),
            }
                               );

            Console.Write("Please enter a sentance: ");
            var sentance = Console.ReadLine();

            // create Arraylist to store misspelled words
            var misspelledWords = new List <string>();

            // first break the sentance up into words,
            string[] words = sentance.Split(' ');

            // then iterate through the list of words using the spell checker
            // capturing distinct words that are misspelled
            foreach (string word in words)
            {
                /**
                 * indicates whether the specified Unicode character
                 * in a word is categorized as a Unicode letter
                 * then add to StringBuilder object
                 */
                var sb = new StringBuilder();
                foreach (char c in word)
                {
                    if (char.IsLetter(c))
                    {
                        sb.Append(c);
                    }
                }

                var strippedWord = sb.ToString();
                Console.WriteLine("Checking \"{0}\"", strippedWord);
                if (!spellChecker.Check(strippedWord) && !misspelledWords.Contains(strippedWord))
                {
                    misspelledWords.Add(strippedWord);
                }
            }
            if (misspelledWords.Count == 0)
            {
                Console.Write("no misspellings");
            }
            else
            {
                Console.Write("misspellings: ");
                foreach (string misspelledWord in misspelledWords)
                {
                    Console.Write("{0} ", misspelledWord);
                }
            }
            Console.ReadKey();
        }
예제 #4
0
        /// <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>
        static void Main(string[] args)
        {
            Console.Write("Please enter a sentence: ");
            var sentence = 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

            string[]      seperators = { "/", ",", ".", "!", "?", ";", ":", " " };
            string[]      words      = sentence.Split(seperators, StringSplitOptions.RemoveEmptyEntries);
            List <string> Misspelled = new List <string>();

            // use this spellChecker to evaluate the words
            var spellChecker = new SpellChecker.Core.SpellChecker
                               (
                new ISpellChecker[]
            {
                // I commented out the MnemoicSpellCheckerIBeforeE because it's unnecessary, irrelevant, and not a very good rule.
                // I did implement the method however which you can see in the class file and it does work as intended
                // Method also runs and passes the NUnit Tests
                // The problem with the rule is that there are numerous exceptions, which don't follow any rules so there's no way to implement it properly
                // Even the examples in the class file that are supposed to be evaluated as misspelled are actually all correct
                // Given a false like on those examples we would need to cross check against the dictionary spellchecker
                // and if it's true, then it gets checked by the dictionary spellchecker anyway,
                // so no matter what, the word has to be checked by the dictionary spellchecker, thus making the Mnemonic spellchecker unnecessary
                // I could leave it running, and call the dictionary spellchecker from within the Mnemonic Check method upon a false result
                // but then we're just running extra code that isn't necessary

                //new MnemonicSpellCheckerIBeforeE(),
                new DictionaryDotComSpellChecker(),
            }
                               );


            foreach (string word in words)
            {
                var result = spellChecker.Check(word);

                if (!result)
                {
                    // make sure the word hasn't already been used
                    if (Misspelled.Contains(word) == false)
                    {
                        Misspelled.Add(word);
                    }
                }
            }

            Console.WriteLine("Here are some possible misspelled words:");
            foreach (string item in Misspelled)
            {
                Console.WriteLine(item);
            }

            // following is needed otherwise the console closes once the program is completed without any time to see the result
            Console.WriteLine("Press enter to exit");
            Console.Read();
        }
예제 #5
0
        /// <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>
        static void Main(string[] args)
        {
            // use this spellChecker to evaluate the words
            var spellChecker = new SpellChecker.Core.SpellChecker
                (
                    new ISpellChecker[]
                    {
                        new MnemonicSpellCheckerIBeforeE(),
                        new DictionaryDotComSpellChecker(),
                    }
                );

            Console.Write("Please enter a sentance: ");
            var sentance = Console.ReadLine();

            // use this ArrayList to accumulate unique words
            var misspelledWords = new List<string>();

            // first break the sentance up into words
            string[] words = sentance.Split(' ');

            // then iterate through the list of words using the spell checker
            // capturing distinct words that are misspelled
            foreach (string word in words)
            {
                // strip word down to letters only
                var sb = new StringBuilder();
                foreach (char c in word)
                {
                    if (char.IsLetter(c))
                    {
                        sb.Append(c);
                    }
                }
                var strippedWord = sb.ToString();
                Console.WriteLine("Checking \"{0}\"", strippedWord);
                if (!spellChecker.Check(strippedWord) && !misspelledWords.Contains(strippedWord))
                {
                    misspelledWords.Add(strippedWord);
                }
            }

            if (misspelledWords.Count == 0)
            {
                Console.Write("[no misspellings]");
            }
            else
            {
                Console.Write("misspellings: ");
                foreach (string misspelledWord in misspelledWords)
                {
                    Console.Write("{0} ", misspelledWord);
                }
            }

            Console.ReadLine(); // for pausing to view output
        }
        /// <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>
        static void Main(string[] args)
        {
            Console.Write("Please enter a sentence: ");
            var sentence = 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 SpellChecker.Core.SpellChecker
                               (
                new ISpellChecker[]
            {
                new MnemonicSpellCheckerIBeforeE(),
                new DictionaryDotComSpellChecker(),
            }
                               );

            var words          = FilterInput(sentence);
            var mispelledWords = new List <String>();

            foreach (string word in words)
            {
                if (spellChecker.Check(word) == false)
                {
                    mispelledWords.Add(word);
                }
            }

            // replace puntuaction with empty string when string ends with punctuation , to prevent false negatives
            // when spell checking

            if (mispelledWords.Count() > 0)
            {
                Console.Write("mispelled words: ");
                foreach (string misspelledWord in mispelledWords)
                {
                    Console.Write("'" + misspelledWord + "' ");
                }
                Console.Write("\r\n");
            }
            else
            {
                Console.WriteLine("No misspelled words.");
            }
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
예제 #7
0
        /// <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>
        static void Main(string[] args)
        {
            Console.Write("Please enter a sentance: ");
            var sentence = 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 SpellChecker.Core.SpellChecker
                               (
                new ISpellChecker[]
            {
                new MnemonicSpellCheckerIBeforeE(),
                new DictionaryDotComSpellChecker(),
            }
                               );
        }
예제 #8
0
        /// <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>
        static void Main(string[] args)
        {
            bool result;

            Console.Write("Please enter a sentance: ");
            var sentance = Console.ReadLine();

            // first break the sentance up into words,
            string[] words = sentance.Split(null);

            // Remove duplicates
            string[] wordsNoDup = words.Distinct().ToArray();

            // 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 SpellChecker.Core.SpellChecker
                               (
                new ISpellChecker[]
            {
                new MnemonicSpellCheckerIBeforeE(),
                new DictionaryDotComSpellChecker(),
            }
                               );

            Console.WriteLine();

            foreach (string item in wordsNoDup)
            {
                result = spellChecker.Check(item);

                if (result == false)
                {
                    Console.WriteLine("The word: " + item + " is spelled incorrectly");
                }
            }

            Console.WriteLine();
            Console.WriteLine("Spell check is complete...");
            Console.ReadKey();
        }
예제 #9
0
        /// <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>
        static void Main(string[] args)
        {
            Console.Write("Please enter a sentance: ");
            var sentence = 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
            string sentenceSanitized = Regex.Replace(sentence, @"[^\w\s']", "");

            string[] arrayWords = sentenceSanitized.Split(' ');

            HashSet <string> distinctInccorectWords = new HashSet <string>();

            // use this spellChecker to evaluate the words
            var spellChecker = new SpellChecker.Core.SpellChecker
                               (
                new ISpellChecker[]
            {
                new MnemonicSpellCheckerIBeforeE(),
                new DictionaryDotComSpellChecker(),
            }
                               );

            foreach (var word in arrayWords)
            {
                if (!spellChecker.Check(word))
                {
                    distinctInccorectWords.Add(word);
                }
            }

            Console.Write("Misspelled words:");
            foreach (var word in distinctInccorectWords)
            {
                Console.Write(" {0}", word);
            }
        }