Пример #1
0
        public void Load(string sourceDir)
        {
            _wordCounter = new WordCounter();
            foreach (var fileName in GetFiles(sourceDir))
            {
                using (var reader = File.OpenText(fileName))
                {
                    WordCounter.AddText(reader, 2);  // words 2 chars or more
                }
            }

            _wordPicker = new WordPicker(WordCounter.WordMap);
        }
Пример #2
0
        static void Main(string[] args)
        {
            if(args.Length <= 0)
            {
                PrintUsage();
                Exit();
            }

            var dirName = args[0];
            if(!Directory.Exists(dirName))
            {
                Console.WriteLine("Directory '{0}' does not exist or is unaccessible.", dirName);
                Exit();
            }

            var wordCounter = new WordCounter();
            foreach(var fileName in GetFiles(dirName))
            {
                using(var reader = File.OpenText(fileName))
                {
                    wordCounter.AddText(reader, 2);  // words 2 chars or more
                }
            }

            foreach(var x in wordCounter.WordMap)
            {
                for(var i = 0; i < x.Value; ++i)
                {
                    Console.WriteLine(x.Key);
                }
            }

            return;

            var rnd = new Random();

            var orderedList = wordCounter.WordMap.OrderByDescending((kvp) => kvp.Value).ToList();
            var minIndex = 0;
            var maxIndex = orderedList.Count - 1;

            foreach(var keyValuePairs in orderedList)
            {
                Console.WriteLine(
                    "{0} [{1}, {2}] : {3}",
                    keyValuePairs.Value,
                    Math.Log(keyValuePairs.Value),
                    rnd.Next(minIndex, maxIndex),
                    keyValuePairs.Key);
            }
        }