예제 #1
0
        // 从本地读取文件,并将文件保存到数据结构中
        public void readFile(ref KeywordDict keywordDict)
        {
            string strLine;

            try
            {
                FileStream   fileStream = new FileStream("keyWord.txt", FileMode.Open);
                StreamReader sr         = new StreamReader(fileStream, System.Text.Encoding.Default);
                strLine = sr.ReadLine();
                while (strLine != null)
                {
                    keywordDict.AddWord(strLine);
                    strLine = sr.ReadLine();
                }
                sr.Close();
                fileStream.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            Common      common      = new Common();
            KeywordDict keywordDict = new KeywordDict();

            common.readFile(ref keywordDict);

            KeywordManager keywordManager = new KeywordManager(keywordDict);

            string pageData = common.readString("test.txt");

            //记录程序运行时间
            Stopwatch myWatch = Stopwatch.StartNew();

            ///对pageData的处理
            keywordManager.CheckNormalWord(pageData);

            //记录程序运行时间并显示
            myWatch.Stop();
            Console.WriteLine("time cost: {0} ms", myWatch.ElapsedMilliseconds.ToString());

            Console.ReadKey();
        }
예제 #3
0
 public KeywordManager(KeywordDict keywordDict)
 {
     this.keywordDict = keywordDict;
 }