Esempio n. 1
0
        public void Load(Corpus good, Corpus bad)
        {
            _good = good;
            _bad = bad;

            CalculateProbabilities();
        }
Esempio n. 2
0
        public void Load(TextReader goodReader, TextReader badReader)
        {
            _good = new Corpus(goodReader);
            _bad = new Corpus(badReader);

            CalculateProbabilities();
        }
Esempio n. 3
0
        public void Load(DataTable table)
        {
            _good = new Corpus();
            _bad = new Corpus();

            foreach (DataRow row in table.Rows)
            {
                bool isSpam = (bool)row["IsSpam"];
                string body = row["Body"].ToString();
                if (isSpam)
                {
                    _bad.LoadFromReader(new StringReader(body));
                }
                else
                {
                    _good.LoadFromReader(new StringReader(body));
                }
            }

            CalculateProbabilities();
        }
        private void loadItem_Click(object sender, RoutedEventArgs e)
        {
            ClearBase();

            Corpus bad = new Corpus();
            Corpus good = new Corpus();
            bad.LoadFromFile("../../Data/spam.txt");
            good.LoadFromFile("../../Data/ham.txt");

            _filter = new SpamFilter();
            _filter.Load(good, bad);

            //FlowDocument d = new FlowDocument();
            //Paragraph p = new Paragraph();

            //p.Inlines.Add(String.Format(@"{0} {1} {2}{3}", _filter.Good.Tokens.Count, _filter.Bad.Tokens.Count, _filter.Prob.Count, Environment.NewLine));

            foreach (string key in _filter.Prob.Keys)
            {
                if (_filter.Prob[key] > 0.02)
                {
                    lst.Add(new WordInfo(key, _filter.Prob[key].ToString("0.0000")));
                    //p.Inlines.Add(String.Format("{0}, {1}{2}", _filter.Prob[key].ToString("0.0000"), key, Environment.NewLine));
                }
            }
            for (int i = 0; i < lst.Count; i++)
            {
                listView1.ItemsSource = lst;
            }
            //d.Blocks.Add(p);
            //txtOut.Document = d;
        }
        void SaveToSpam()
        {
            try
            {
                TextRange textRange = new TextRange(txtOut.Document.ContentStart, txtOut.Document.ContentEnd);
                string body = textRange.Text;
                using (StreamWriter sw = new StreamWriter("../../Data/spam.txt", true, System.Text.Encoding.Default))
                {
                    sw.Write(Environment.NewLine);
                    sw.Write(body);
                }

                ClearBase();

                Corpus bad = new Corpus();
                Corpus good = new Corpus();
                bad.LoadFromFile("../../Data/spam.txt");
                good.LoadFromFile("../../Data/ham.txt");

                _filter = new SpamFilter();
                _filter.Load(good, bad);

                foreach (string key in _filter.Prob.Keys)
                {
                    if (_filter.Prob[key] > 0.02)
                    {
                        lst.Add(new WordInfo(key, _filter.Prob[key].ToString("0.0000")));
                    }
                }

                for (int i = 0; i < lst.Count; i++)
                {
                    listView1.ItemsSource = lst;
                }

                _filter.ToFile("../../Data/out.txt");

            }
            catch
            {
                MessageBox.Show("Error.");
            }
        }