/*
         *  The Main class of the program.
         *  It should allow the user to pass to text files for analysis as CLI arguments.
         *  Also, measure  the time of the program's execution. For example:
         *  >dotnet run -- text1.txt text2.txt
         */
        public static void Main(string[] args)
        {
            View                myView = new View();
            string              filePath;
            FileContent         sourceFile;
            StatisticalAnalysis myAnalysis;
            StatisticalAnalysis myAnalysis1;

            if (args.Length > 0)
            {
                for (int index = 0; index < args.Length; index++)
                {
                    filePath = String.Format(args[index]);
                    Console.WriteLine("Analysis Of File {0} ", filePath.ToUpper());
                    sourceFile  = new FileContent(filePath);
                    myAnalysis  = new StatisticalAnalysis(sourceFile.CharIterator());
                    myAnalysis1 = new StatisticalAnalysis(sourceFile.WordIterator());
                    myView.Print(myAnalysis.CountOf("a", "e", "i", "o", "u"), "Number of vowels: ");
                    myView.Print(myAnalysis1.DictionarySize(), "Number of unique Words: ");
                    myView.Print(myAnalysis.Size(), "Total number of characters: ");
                    myView.PrintList(myAnalysis1.OccurMoreThan(5), "Words that repeats more than 5 times: ");
                    Console.WriteLine();
                }
            }

            // FileContent sourceFile = new FileContent( filePath );
            // StatisticalAnalysis myAnalysis = new StatisticalAnalysis( sourceFile.CharIterator() );
            // StatisticalAnalysis myAnalysis1 = new StatisticalAnalysis( sourceFile.WordIterator() );
            // myView.Print( myAnalysis1.CountOf( "it", "is" ), "Number of vowels: ");
            // myView.Print( myAnalysis1.DictionarySize(), "Number of unique elements: ");
            // myView.Print( myAnalysis1.Size(), "Total number of characters: ");
            // myView.PrintList( myAnalysis1.OccurMoreThan( 5 ), "Element that repeats 5 times: " );
        }
예제 #2
0
        static void Main(string[] args)
        {
            var time = System.Diagnostics.Stopwatch.StartNew();

            foreach (var path in args)
            {
                var fileContent   = new FileContent(path);
                var charsAnalysis = new StatisticalAnalysis(fileContent.CharIterator());
                var wordsAnalysis = new StatisticalAnalysis(fileContent.WordIterator());
                // Print results of the analysis
                Console.WriteLine($"---{path}---");
                Console.WriteLine("Char count: " + charsAnalysis.Size);
                Console.WriteLine("Word count: " + wordsAnalysis.Size);
                Console.WriteLine("Dict size: " + wordsAnalysis.DictionarySize);
                Console.Write("Most used words (>1%): ");
                View.Print(wordsAnalysis.OccurMoreThan(wordsAnalysis.Size / 100));
                Console.WriteLine("'love' count: " + wordsAnalysis.CountOf("love"));
                Console.WriteLine("'hate' count: " + wordsAnalysis.CountOf("hate"));
                Console.WriteLine("'music' count: " + wordsAnalysis.CountOf("music"));
                Console.WriteLine("vowels %: " +
                                  Round(charsAnalysis.CountOf("a", "o", "i", "e", "u") * 100.0 / charsAnalysis.Size, 2));
                Console.WriteLine("a:e count ratio: " +
                                  Round((double)charsAnalysis.CountOf("a") / charsAnalysis.CountOf("e"), 2));
                var charsStatistic = charsAnalysis.ElementsDictionary
                                     .Select(kvp => (kvp.Key.ToUpper(), Round(kvp.Value * 100.0 / charsAnalysis.Size, 2)))
                                     .ToDictionary(t => t.Item1, t => t.Item2);
                View.Print(charsStatistic);
            }
            time.Stop();
            double elapsedTime = time.ElapsedMilliseconds / 1000.0;

            Console.WriteLine($"Benchmark time: {elapsedTime} secs");
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to TEXT ANALYSER!");
            for (int i = 0; i < args.Length; i++)
            {
                var nFileContent      = new FileContent(args[i]);
                var charfileAnalysis  = new StatisticalAnalysis(nFileContent.CharIterator());
                var wordsfileAnalysis = new StatisticalAnalysis(nFileContent.WordIterator());
                var wordsView         = wordsfileAnalysis.displayStats;
                var charsView         = charfileAnalysis.displayStats;

                //Printing output
                Console.WriteLine($"---{args[i]}---");
                //Number of words
                var nOfWords = wordsfileAnalysis.Size();
                wordsView.Print("Words count: " + nOfWords.ToString());

                //Number of chars
                var nOfChars = charfileAnalysis.Size();
                charsView.Print("Chars count: " + nOfChars.ToString());

                //Dict size
                var nOfUniqueWords = wordsfileAnalysis.DictionarySize();
                wordsView.Print("Dict size: " + nOfUniqueWords.ToString());

                // Most used words
                int           _limit           = wordsfileAnalysis.Size() / 100;
                List <string> wordsMoreThanOne = wordsfileAnalysis.OccurMoreThan(_limit).ToList <string>();
                var           words            = new List <string>();
                words.Add("Words that consists of >1%: [");
                words.Add(String.Join(", ", wordsMoreThanOne));
                words.Add("]");
                wordsView.Print(words);
                Console.WriteLine();

                //`'love' count: 60` number of times that the word ‘love’ occurred
                var _love = wordsfileAnalysis.CountOf("love");
                wordsView.Print($"'love' count: {_love}");

                //`'hate' count: 4` number of times that the word ‘hate’ occurred * *
                var _hate = wordsfileAnalysis.CountOf("hate");
                wordsView.Print($"'hate' count: {_hate}");

                //`'music' count: 4` number of times that the word ‘music’ occurred
                var _music = wordsfileAnalysis.CountOf("music");

                wordsView.Print($"'music' count: {_music}");

                //`vowels %: 38` what part of all characters are vowels(a, o, i, e, u)

                //`a: e count ratio: 1.54 ` the ratio of ‘a’ to ‘e’ occurrences

                //`[G -> 2.16] [R -> 5.36] .... < and the rest>` % of in whole text of all the letters

                //wordsView.Print(wordsfileAnalysis.resultDict, 0);
            }
        }
        static void Main(string[] args)
        {
            View PrintFunction = new View();

            PrintFunction.PrintStart();
            //string NameFile = Console.ReadLine();
            string NameFile = "/Users/nataliafilipek/Desktop/OOP/csharp-text-analyser-Natalia1004/test2.txt";

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            FileContent         AnalyzedText = new FileContent(NameFile);
            StatisticalAnalysis AnalazedChar = new StatisticalAnalysis(AnalyzedText.CharIterator());
            StatisticalAnalysis AnalazedWord = new StatisticalAnalysis(AnalyzedText.WordIterator());

            PrintFunction.PrintMenuUser();
            string UserChoice = null;

            while (UserChoice != "0")
            {
                Console.WriteLine("What do You want to do now?");
                UserChoice = Console.ReadLine();

                if (UserChoice == "1a")
                {
                    Console.WriteLine("List of Chars:");
                    var chars      = Console.ReadLine();
                    var arrayChars = chars.Split(",");
                    Console.WriteLine(AnalazedChar.CountOf(arrayChars));
                    continue;
                }
                else if (UserChoice == "1b")
                {
                    Console.WriteLine("List of Words:");
                    var words      = Console.ReadLine();
                    var arrayWords = words.Split(",");
                    Console.WriteLine(AnalazedWord.CountOf(arrayWords));
                    continue;
                }
                else if (UserChoice == "2a")
                {
                    Console.WriteLine("All of unique chars is:");
                    Console.WriteLine(AnalazedChar.DictionarySize());
                    continue;
                }
                else if (UserChoice == "2b")
                {
                    Console.WriteLine("All of unique words is:");
                    Console.WriteLine(AnalazedWord.DictionarySize());
                    continue;
                }
                else if (UserChoice == "3a")
                {
                    Console.WriteLine("Total nmber of chars is:");
                    Console.WriteLine(AnalazedChar.Size());
                    continue;
                }
                else if (UserChoice == "3b")
                {
                    Console.WriteLine("Total nmber of words is:");
                    Console.WriteLine(AnalazedWord.Size());
                    continue;
                }
                else if (UserChoice == "4a")
                {
                    Console.WriteLine("Select number of occurences:");
                    int NumberOccurences = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine(AnalazedChar.OccurMoreThan(NumberOccurences));
                    continue;
                }
                else if (UserChoice == "4b")
                {
                    Console.WriteLine("Select number of occurences:");
                    int NumberOccurences = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine(AnalazedWord.OccurMoreThan(NumberOccurences));
                    continue;
                }
                else if (UserChoice == "5")
                {
                    Console.WriteLine("Select first and second char");
                    string first  = Console.ReadLine();
                    string second = Console.ReadLine();
                    Console.WriteLine(AnalazedChar.CountRatio(first, second));
                }
                if (UserChoice == "6a")
                {
                    Console.WriteLine("List of Chars:");
                    var chars      = Console.ReadLine();
                    var arrayChars = chars.Split(",");
                    PrintFunction.Print(arrayChars, AnalazedChar.CharToWholeText(arrayChars));
                    continue;
                }
                else if (UserChoice == "6b")
                {
                    Console.WriteLine("List of Words:");
                    var words      = Console.ReadLine();
                    var arrayWords = words.Split(",");
                    Console.WriteLine(AnalazedWord.CharToWholeText(arrayWords));
                    continue;
                }
            }
            PrintFunction.PrintQuit();

            stopwatch.Stop();
            TimeSpan stopwatchElapsed = stopwatch.Elapsed;

            Console.WriteLine(stopwatchElapsed);
        }