Exemplo n.º 1
0
 public CharIterator(FileContent content)
 {
     if(File.Exists(content.GetFilename()))
     {
         data = File.ReadAllText(content.GetFilename());
     }
     else
     {
         Console.WriteLine("File does not exists");
     }
 } // End of constructor
Exemplo n.º 2
0
 public WordIterator(FileContent content)
 {
     if(File.Exists(content.GetFilename()))
     {
         StreamReader reader = new StreamReader(content.GetFilename());
         // data = File.ReadAllLines(content.GetFilename());
         data = reader.ReadToEnd().Split(' ');
     }
     else
     {
         Console.WriteLine("File does not exists");
     }
 } // End of constructor
        private static void PrintAllData(FileContent TextToAnalyze, StatisticalAnalysis CharAnalyzer, StatisticalAnalysis WordAnalyzer, string elapsedTime, string path)
        {
            if (TextToAnalyze.FileContentAsString.Length == 0)
            {
                throw new ArgumentException($"The file '{Path.GetFileName(path)}' is empty. No statistics available.");
            }

            View ResultData = new View();

            Console.OutputEncoding = Encoding.UTF8;

            ResultData.Print(TextToAnalyze.GetFilename());
            ResultData.Print($"Char count: {Convert.ToString(CharAnalyzer.Size())}");
            ResultData.Print($"Word count: {Convert.ToString(WordAnalyzer.Size())}");
            ResultData.Print($"Dict size: {Convert.ToString(WordAnalyzer.DictionarySize())}");
            ResultData.Print(WordAnalyzer.GetListOfWordsAbovePercentage(percentage: 1));
            ResultData.Print(WordAnalyzer.CountOf(InterestingWords));
            ResultData.Print($"vowels %: {Convert.ToString(CharAnalyzer.GetVowelPercentage())}");
            try
            {
                ResultData.Print($"a:e count ratio : {Convert.ToString(CharAnalyzer.GetRatioOfAtoE())}");
            }
            catch (ArgumentException ex)
            {
                ResultData.Print($"a:e count ratio : {ex.Message}");
            }
            ResultData.Print(CharAnalyzer.GetPecentageFromOccurences());
            ResultData.Print($"Benchmark time: {elapsedTime}");
        }