Esempio n. 1
0
        static void Main(string[] args)
        {
            var options = new Options();

            Parser.Default.ParseArguments <Options>(args).WithParsed(Run);
            //Console.WriteLine(FilePath);
            string text = File.ReadAllText(FilePath).ToLower();//读取txt文件

            CountLine countLine = new CountLine();
            int       lines     = countLine.CountLines(text);//行数

            Console.WriteLine("Lines:{0}", lines);

            CountChar countChar = new CountChar();
            int       charnum   = countChar.characSum(text);//字符数

            Console.WriteLine("Characters:{0}", charnum);

            CountWords countWords = new CountWords();
            ArrayList  al         = countWords.Splitwords(text);



            //ArrayList bl = countWords.Splitlenth(3, text);//限定长度

            //单词总数
            int sum = countWords.Sumword(al);

            Console.WriteLine("Wordnumber:{0}", sum);

            //输出最高词频单词,默认前10,可以根据命令行更改个数
            Console.WriteLine("-----------------------输出最高词频单词,命令行配置初始化为前10---------------------------------------------");
            Dictionary <string, int> nary = countWords.countWords(al);

            nary = countWords.sort(nary);
            foreach (KeyValuePair <string, int> entry in nary.Take(Number))
            {
                string       word      = entry.Key;
                int          frequency = entry.Value;
                StreamWriter stream    = new StreamWriter(outputPath, true);
                stream.WriteLine(word + frequency);
                stream.Close();
                Console.WriteLine("{0}:{1}", word, frequency);
            }


            //附加功能,输出指定长度词组,默认为0.
            if (Size != 0)
            {
                Console.WriteLine("-----------------------输出指定长度词组,命令行配置初始化为3---------------------------------------------");
                Dictionary <string, int> test = new Dictionary <string, int>();
                test = countWords.msort(al, Size);
                foreach (var pair in test)
                {
                    Console.WriteLine("{0}:{1}", pair.Key, pair.Value);
                }
            }


            //Console.WriteLine("-----------------------小组附加功能:输出指定长度单词,默认为3--------------------------------------");

            //额外添加功能,输出指定长度的单词
            //Dictionary<string, int> damn = countWords.countWords(bl);
            //foreach (KeyValuePair<string, int> fire in damn)
            //{
            //    Console.WriteLine("{0}:{1}", fire.Key, fire.Value);
            //}
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //string input = Console.ReadLine();//输入
            //string[] inputstr = input.Split(' ');//将输入分成两个小块
            //string path = inputstr[1];//取文件名,文件创建在debug文件夹里
            //string start = inputstr[0];
            string FilePath   = "";
            string outputPath = "";

            var arguments = CommandLineArgumentParser.Parse(args);
            var ar        = arguments.Get("-i");
            var arr       = arguments.Get("-o");

            if (ar != null)
            {
                if (ar.Take() != null)
                {
                    FilePath = ar.Take();
                }
            }
            if (arr != null)
            {
                if (arr.Take() != null)
                {
                    outputPath = arr.Take();
                }
            }


            string text = File.ReadAllText(FilePath).ToLower();//读取txt文件

            CountLine countLine = new CountLine();
            int       lines     = countLine.CountLines(text);//行数

            Console.WriteLine("Lines:{0}", lines);

            CountChar countChar = new CountChar();
            long      charnum   = countChar.characSum(text);//字符数

            Console.WriteLine("Characters:{0}", charnum);

            CountWords countWords = new CountWords();
            ArrayList  al         = countWords.Splitwords(text); //前十

            ArrayList bl  = countWords.Splitlenth(5, text);      //限定长度
            int       sum = countWords.Sumword(al);

            Console.WriteLine("Wordnumber:{0}", sum);

            /*
             * Dictionary<string, int> damn = countWords.countWords(bl);
             * foreach(KeyValuePair<string,int> fire in damn)
             * {
             *  Console.WriteLine("{0}:{1}", fire.Key, fire.Value);
             * }*/

            Console.WriteLine("------------------------------分割线-------------------------------");

            Dictionary <string, int> nary = countWords.countWords(al);

            nary = countWords.sort(nary);
            foreach (KeyValuePair <string, int> entry in nary.Take(10))
            {
                string word      = entry.Key;
                int    frequency = entry.Value;
                Console.WriteLine("{0}:{1}", word, frequency);
            }
        }