Ejemplo n.º 1
0
        public void CalculateWordPairFrequencyTest(Uri uri, int top)
        {
            var fc = new FrequencyCalculator();
            var f  = fc.CalculateWordPairFrequency(uri, top).ToList();

            Assert.Greater(f.Count, 0);
        }
        private void BackgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            var startTime  = DateTime.Now;
            var fc         = new FrequencyCalculator();
            var depth      = Convert.ToByte(numericUpDown1.Value);
            var downloader = new Downloader(depth);
            var t          = downloader.GetTextFromUrlAsync(link);

            while (t.Status == TaskStatus.Running || t.Status == TaskStatus.WaitingForActivation)
            {
                var progress = Math.Round((90.0f * downloader.PresentLevel) / depth);
                if (progress >= 90)
                {
                    progress = 89;
                }
                backgroundWorker1.ReportProgress(Convert.ToInt32(progress));
                Thread.Sleep(1000);
            }
            var content = t.Result;

            //var content = new Downloader(depth).GetTextFromUrl(link);
            backgroundWorker1.ReportProgress(90, content);
            IEnumerable <PhraseFrequency> res;

            if (e.Argument.ToString() == "1")
            {
                res = fc.CalculateWordFrequency(content, 10);
            }
            else
            {
                res = fc.CalculateWordPairFrequency(content, 10);
            }
            backgroundWorker1.ReportProgress(95, res);
            backgroundWorker1.ReportProgress(100, DateTime.Now.Subtract(startTime).TotalSeconds);
        }