static void Main(string[] args)
        {
            Console.WriteLine("Enter a word:");

            var word = Console.ReadLine();

            IEnumerable <string> words = WordListLoader.Load(
                @"D:\Projects\perth-code-dojo-5-anagram-algorithm\AnagramAlgorithm\AlgorithmEngine\App_Data\wordlist.txt")
                                         .Where(w => w.Length >= 3 &&
                                                Regex.IsMatch(w.ToString(), @"^[a-z]+$"));

            Console.Write(word + " - ");

            List <string> matches = AnagramEngine.Find(word, words.ToList());

            matches = matches.OrderBy(m => m.Length).ToList();

            if (matches.Count == 0)
            {
                Console.WriteLine("No matches found!");
            }

            foreach (var match in matches)
            {
                Console.Write(match + " ");
            }
            Console.WriteLine();

            Console.ReadLine();
        }
示例#2
0
        public void Find()
        {
            IEnumerable <string> words = WordListLoader.Load(
                @"D:\Projects\perth-code-dojo-5-anagram-algorithm\AnagramAlgorithm\AlgorithmEngine\App_Data\wordlist.txt")
                                         .Where(w => w.Length >= 3 &&
                                                Regex.IsMatch(w.ToString(), @"^[a-z]+$"));

            var sw = new Stopwatch();

            sw.Reset();
            sw.Start();

            TestTimer tt = new TestTimer();

            tt.Start();

            List <string> matches = AnagramEngine.Find("webster", words.ToList());

            Console.Write("webster" + " - ");

            foreach (var match in matches)
            {
                Console.Write(match + " ");
            }

            tt.Start();
            Console.WriteLine(tt.ElapsedMilliseconds);

            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);

            //600 - 700 list

            //450 - 550
        }
        static void Main(string[] args)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            //Refactoring filtering down

            IEnumerable <string> words = WordListLoader.Load(@"D:\Projects\perth-code-dojo-5-anagram-algorithm\AnagramAlgorithm\AlgorithmEngine\App_Data\wordlist.txt")
                                         .Where(w => w.Length >= 3 &&
                                                Regex.IsMatch(w.ToString(), @"^[a-z]+$"));

            foreach (var word in words)
            {
                Console.Write(word + " - ");

                List <string> matches = AnagramEngine.Find(word, words.ToList());

                foreach (var match in matches)
                {
                    Console.Write(match + " ");
                }
                Console.WriteLine();
            }

            stopwatch.Stop();

            Console.WriteLine("Time to completion -" + stopwatch.ElapsedMilliseconds);

            Console.ReadLine();
        }
示例#4
0
        private static async Task <int> SpellcheckAsync(SpellcheckCommandLineOptions options)
        {
            if (!TryParseOptionValueAsEnumFlags(
                    options.Scope,
                    OptionNames.Scope,
                    out SpellingScopeFilter scopeFilter,
                    SpellingScopeFilter.Comment | SpellingScopeFilter.Region | SpellingScopeFilter.Symbol))
            {
                return(ExitCodes.Error);
            }

            if (!TryParseOptionValueAsEnumFlags(options.IgnoredScope, OptionNames.IgnoredScope, out SpellingScopeFilter ignoredScopeFilter, SpellingScopeFilter.None))
            {
                return(ExitCodes.Error);
            }

            scopeFilter &= ~ignoredScopeFilter;

            if (!TryParseOptionValueAsEnum(options.Visibility, OptionNames.Visibility, out Visibility visibility))
            {
                return(ExitCodes.Error);
            }

            if (!options.TryGetProjectFilter(out ProjectFilter projectFilter))
            {
                return(ExitCodes.Error);
            }

            if (!ParseHelpers.TryEnsureFullPath(options.Words, out ImmutableArray <string> wordListPaths))
            {
                return(ExitCodes.Error);
            }

            if (!TryParsePaths(options.Paths, out ImmutableArray <string> paths))
            {
                return(ExitCodes.Error);
            }

            WordListLoaderResult loaderResult = WordListLoader.Load(
                wordListPaths,
                options.MinWordLength,
                options.MaxWordLength,
                (options.CaseSensitive) ? WordListLoadOptions.None : WordListLoadOptions.IgnoreCase);

            var data = new SpellingData(loaderResult.List, loaderResult.CaseSensitiveList, loaderResult.FixList);

            var command = new SpellcheckCommand(options, projectFilter, data, visibility, scopeFilter);

            CommandStatus status = await command.ExecuteAsync(paths, options.MSBuildPath, options.Properties);

            return(GetExitCode(status));
        }
示例#5
0
        public bool TryParse(SpellcheckCommandOptions options)
        {
            var baseOptions = (CommonReplaceCommandOptions)options;

            if (!TryParse(baseOptions))
            {
                return(false);
            }

            options = (SpellcheckCommandOptions)baseOptions;

            Regex?wordRegex = null;

            if (!TryEnsureFullPath(Words, out ImmutableArray <string> wordListPaths))
            {
                return(false);
            }
#if DEBUG
            if (Word.Any())
            {
                if (!FilterParser.TryParse(
                        Word,
                        OptionNames.Word,
                        OptionValueProviders.PatternOptions_Word_Provider,
                        out Filter? wordFilter))
                {
                    return(false);
                }

                wordRegex = wordFilter !.Regex;
            }
#endif
            WordListLoaderResult result = WordListLoader.Load(
                wordListPaths,
                minWordLength: MinWordLength,
                (CaseSensitive) ? WordListLoadOptions.None : WordListLoadOptions.IgnoreCase);

            var data = new SpellingData(result.List, result.CaseSensitiveList, result.FixList);

            var spellcheckerOptions = new SpellcheckerOptions(
                SplitMode.CaseAndHyphen,
                MinWordLength);

            var spellchecker = new Spellchecker(data, wordRegex, spellcheckerOptions);

            options.Replacer = new SpellcheckState(spellchecker, data);

            return(true);
        }
        public void LoadSimpleWordList()
        {
            IEnumerable <string> words = WordListLoader.Load(@"D:\Projects\perth-code-dojo-5-anagram-algorithm\AnagramAlgorithm\AlgorithmEngine\App_Data\simpewordlist.txt"); // relative ?

            Assert.Equal(5, words.ToList().Count);
        }