public void ClearBase()
 {
     listView1.ItemsSource = null;
     listView1.Items.Clear();
     _filter = null;
     lst.Clear();
 }
        private void fromItem_Click(object sender, RoutedEventArgs e)
        {
            ClearBase();

            _filter = new SpamFilter();
            _filter.FromFile("../../Data/out.txt");

            //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.");
            }
        }