/// <summary>
        /// Detects the language by finding the  top french words, and top english 
        /// PRECONDITION: french stem and english stem must have been run at least once
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDetectLanguage_Click(object sender, EventArgs e)
        {
            //get the most popular french words
            IEnumerable<string> topFrench = GetMostPopularWords(_frenchStemmedCounts);
            //get the most popular english words
            IEnumerable<string> topEnglish = GetMostPopularWords(_englishStemmedCounts);

            int frenchCounter = 0;
            int englishCounter = 0;

            FrenchStemmer frenchStemmer = new FrenchStemmer();
            PorterStemmer englishStemmer = new PorterStemmer();

            //find the top french in text
            string input = this.txtInput.Text;
            foreach (string term in input.Split(' '))
            {
                string frenchStem = frenchStemmer.stemTerm(term);
                string englishStem = englishStemmer.stemTerm(term);

                if (string.IsNullOrEmpty(term))
                    continue;
                foreach (string frenchTerm in topFrench)
                {
                   // if (frenchTerm.IgnoringCaseEquals(term))
                    if (frenchTerm.IgnoringCaseEquals(frenchStem))
                        frenchCounter++;
                }

                foreach (string englishTerm in topEnglish)
                {
                   // if (englishTerm.IgnoringCaseEquals(term))
                    if (englishTerm.IgnoringCaseEquals(englishStem))
                        englishCounter++;
                }

            }

            if (frenchCounter > englishCounter)
                MessageBox.Show("French");
            else if (englishCounter > frenchCounter)
                MessageBox.Show("English");
            else
                MessageBox.Show("Not sure, have you run a stem on each language to train it?");
        }
        /// <summary>
        /// Does a stemming of the text in english, with step by step output.
        /// </summary>
        private void btnEnglishStem_Click(object sender, EventArgs e)
        {
            string input = txtInput.Text;
            this.txtOutput.Text = "";
            this.txtFinalText.Text = "";

            foreach (string term in input.Split(' '))
            {
                if (string.IsNullOrEmpty(term))
                    continue;

                //check that its actually goign to do anything
                PorterStemmer preStemmer = new PorterStemmer();
                string stemmedTerm = preStemmer.stemTerm(term);

                //save the stemmed term to the stemmed counts
                // do this before you skip it if its already done
                if (_englishStemmedCounts.ContainsKey(stemmedTerm))
                {
                    _englishStemmedCounts[stemmedTerm]++;
                }
                else
                {
                    _englishStemmedCounts.Add(stemmedTerm, 1);
                }

                txtFinalText.Text += stemmedTerm + " ";
                if (term.Equals(stemmedTerm))
                    continue;

                //expand out the steps in full
                PorterStemmer stemmer = new PorterStemmer();
                stemmer.setTerm(term);
                stemmer.PreStem();
                // txtOutput.Text += term + @" -> " + stemmer.stemTerm(term) + Environment.NewLine;
                stemmer.Step1();
                txtOutput.Text += term + " Step 1 " + stemmer.getCurentstate() + Environment.NewLine;
                stemmer.Step2();
                txtOutput.Text += term + " Step 2 " + stemmer.getCurentstate() + Environment.NewLine;
                stemmer.Step3();
                txtOutput.Text += term + " Step 3 " + stemmer.getCurentstate() + Environment.NewLine;
                stemmer.Step4();
                txtOutput.Text += term + " Step 4 " + stemmer.getCurentstate() + Environment.NewLine;
                stemmer.Step5();
                txtOutput.Text += term + " Step 5 " + stemmer.getCurentstate() + Environment.NewLine;
                stemmer.Step6();
                txtOutput.Text += term + " Step 6 " + stemmer.getCurentstate() + Environment.NewLine;
                txtOutput.Text += Environment.NewLine;
                stemmer.PostStem();

                txtOutput.Text += "Final Stem: " + stemmer.getTerm() + Environment.NewLine + Environment.NewLine;

            }
        }
        /// <summary>
        /// Does a stemming of the text in english, with step by step output.
        /// </summary>
        private void btnEnglishStem_Click(object sender, EventArgs e)
        {
            string input = txtInput.Text;

            this.txtOutput.Text    = "";
            this.txtFinalText.Text = "";

            foreach (string term in input.Split(' '))
            {
                if (string.IsNullOrEmpty(term))
                {
                    continue;
                }

                //check that its actually goign to do anything
                PorterStemmer preStemmer  = new PorterStemmer();
                string        stemmedTerm = preStemmer.stemTerm(term);


                //save the stemmed term to the stemmed counts
                // do this before you skip it if its already done
                if (_englishStemmedCounts.ContainsKey(stemmedTerm))
                {
                    _englishStemmedCounts[stemmedTerm]++;
                }
                else
                {
                    _englishStemmedCounts.Add(stemmedTerm, 1);
                }


                txtFinalText.Text += stemmedTerm + " ";
                if (term.Equals(stemmedTerm))
                {
                    continue;
                }


                //expand out the steps in full
                PorterStemmer stemmer = new PorterStemmer();
                stemmer.setTerm(term);
                stemmer.PreStem();
                // txtOutput.Text += term + @" -> " + stemmer.stemTerm(term) + Environment.NewLine;
                stemmer.Step1();
                txtOutput.Text += term + " Step 1 " + stemmer.getCurentstate() + Environment.NewLine;
                stemmer.Step2();
                txtOutput.Text += term + " Step 2 " + stemmer.getCurentstate() + Environment.NewLine;
                stemmer.Step3();
                txtOutput.Text += term + " Step 3 " + stemmer.getCurentstate() + Environment.NewLine;
                stemmer.Step4();
                txtOutput.Text += term + " Step 4 " + stemmer.getCurentstate() + Environment.NewLine;
                stemmer.Step5();
                txtOutput.Text += term + " Step 5 " + stemmer.getCurentstate() + Environment.NewLine;
                stemmer.Step6();
                txtOutput.Text += term + " Step 6 " + stemmer.getCurentstate() + Environment.NewLine;
                txtOutput.Text += Environment.NewLine;
                stemmer.PostStem();



                txtOutput.Text += "Final Stem: " + stemmer.getTerm() + Environment.NewLine + Environment.NewLine;
            }
        }