Exemple #1
0
        public static void ListWords()
        {
            TextInfo      tx          = CultureInfo.CurrentCulture.TextInfo;
            int           amount      = 0;
            bool          exitLoop    = false;
            List <string> chosenWords = new List <string>();
            Func <KeyValuePair <string, int>, bool> filter = pair => String.IsNullOrEmpty(pair.Key);

            var filterdWords = SortedWords.Where(filter).ToList();
            int wordsCount   = filterdWords.Count();

            do
            {
                Clear();
                filterdWords = SortedWords.Where(filter).ToList();

                WriteLine("Word        Count          % of total words");
                WriteLine("-----------------------------------------");



                for (int i = 0; i < wordsCount; i++)
                {
                    WriteLine(tx.ToTitleCase(filterdWords[i].Key.ToLower()).PadRight(15, ' ') + filterdWords[i].Value.ToString().PadRight(15, ' ') + ((filterdWords[i].Value / SortedWords.Count) * 100));

                    chosenWords.Add(tx.ToTitleCase(filterdWords[i].Key.ToLower()));
                }



                WriteLine("Press 1 to sort out specified number of top words");
                WriteLine("Press 2 to sort out words with count more than specified number");
                WriteLine("Press 3 to display all words");
                WriteLine("Press enter to save current list to txt");
                WriteLine("Press escape to exit to main menu");

                ConsoleKeyInfo input;
                bool           isValidKey;

                do
                {
                    input = ReadKey(true);

                    isValidKey = input.Key == ConsoleKey.D1 || input.Key == ConsoleKey.D2 || input.Key == ConsoleKey.D3 || input.Key == ConsoleKey.Escape || input.Key == ConsoleKey.Enter;
                } while (!isValidKey);

                if (input.Key == ConsoleKey.D1)
                {
                    Write("\nDisplay top: ");
                    wordsCount = Convert.ToInt32(ReadLine());

                    filter = pair => !String.IsNullOrEmpty(pair.Key);
                }
                if (input.Key == ConsoleKey.D2)
                {
                    WriteLine("\nCount more than: ");
                    amount = Convert.ToInt32(ReadLine());

                    filter = pair => pair.Value > amount;
                }
                if (input.Key == ConsoleKey.D3)
                {
                    filter = pair => !String.IsNullOrEmpty(pair.Key);
                }


                if (input.Key == ConsoleKey.Escape)
                {
                    exitLoop = true;
                }



                if (input.Key == ConsoleKey.Enter)
                {
                    TextFileProsessing.WritCurrentListToTxt(chosenWords);
                }
            } while (!exitLoop);
        }
Exemple #2
0
 public static void DeleteNewIgnoredWords()
 {
     SortedWords = DeleteIgnoredWords(TextFileProsessing.WordsToIgnore(Program.ignorelistLocation), SortedWords);
 }
        static async Task Menu()
        {
            string source;
            bool   shouldNotExit = true;

            while (shouldNotExit)
            {
                Clear();

                WriteLine("1. Get words from Web source");
                WriteLine("2. Get links from Web source");
                WriteLine("3. Read text source");
                WriteLine("4. List words");
                WriteLine("5. List Links");
                WriteLine("6. Exit");

                ConsoleKeyInfo keyPressed = ReadKey(true);


                switch (keyPressed.Key)
                {
                case ConsoleKey.D1:

                    try
                    {
                        Clear();

                        Write("Enter websource uri: ");
                        source = ReadLine();

                        string scrapedWebdWords = await client.GetStringAsync(source);

                        WordProsessing.ProcessWordsFromScrapedString(scrapedWebdWords);

                        TextFileProsessing.WriteToGatherdWOrdsAndCOuntxt();
                    }
                    catch (Exception e)
                    {
                        WriteLine(e);
                        ReadKey();
                    }


                    break;


                case ConsoleKey.D2:

                    try
                    {
                        Clear();

                        Write("Enter websource uri: ");
                        source = ReadLine();

                        string scrapedWebdString = await client.GetStringAsync(source);

                        WordProsessing.GetLinksFromWebPage(scrapedWebdString);

                        TextFileProsessing.WriteToGatherdWOrdsAndCOuntxt();
                    }
                    catch (Exception e)
                    {
                        WriteLine(e);
                        ReadKey();
                    }


                    break;



                case ConsoleKey.D3:

                    try
                    {
                        Clear();
                        Write("Enter textfile path: ");
                        source = ReadLine();

                        string scrapedTextFiledWords = TextFileProsessing.TextfileReader($"{source}");

                        WordProsessing.ProcessWordsFromScrapedString(scrapedTextFiledWords);

                        TextFileProsessing.WriteToGatherdWOrdsAndCOuntxt();
                    }
                    catch (Exception e)
                    {
                        WriteLine(e);
                        ReadKey();
                    }

                    break;

                case ConsoleKey.D4:

                    Clear();

                    WordProsessing.ListWords();

                    break;

                case ConsoleKey.D5:

                    Clear();

                    foreach (var link in WordProsessing.Links)
                    {
                        WriteLine(link);
                    }

                    ReadKey(true);

                    break;


                case ConsoleKey.D6:

                    shouldNotExit = false;

                    break;
                }

                WordProsessing.DeleteNewIgnoredWords();
                WordProsessing.SortedWords = WordProsessing.SortedWords.OrderByDescending(x => x.Value);
            }

            TextFileProsessing.WriteToGatherdWOrdsAndCOuntxt();
        }
Exemple #4
0
        public static void ProcessWordsFromScrapedString(string scrapedString)
        {
            Dictionary <string, int> sortedCountedWords = WordCountSorter(WordScraper(scrapedString));

            SortedWords = DeleteIgnoredWords(TextFileProsessing.WordsToIgnore(Program.ignorelistLocation), sortedCountedWords);
        }
        static void Main(string[] args)
        {
            WordProsessing.SortedWords = TextFileProsessing.ReadFromGatherdWOrdsAndCOuntxt();

            Menu().Wait();
        }