Esempio n. 1
0
        /// <summary>
        /// event handler for incrementation of sentences - button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            sentList = new SentenceList(txt);

            //incrementation by button
            if (numericUpDown1.Value > sentList.Sentences.Count)
            {
                numericUpDown1.Value = sentList.Sentences.Count;
            }
            else
            {
                numericUpDown1.Value++;
            }
            int locate = (int)numericUpDown1.Value;

            if (locate > -1 && locate < sentList.Sentences.Count - 1)
            {
                textBox4.Text = sentList.Sentences[locate].FullSentence;
                textBox5.Text = sentList.Sentences[locate].WordCount.ToString();
                string s;
                textBox6.Text = s = string.Format("{0:0.00}", sentList.Sentences[locate].AvgWordLength);
            }
            else
            {
                textBox4.Text = "There isn't anymore sentences to be displayed.";
                textBox5.Text = "0";
                textBox6.Text = "0.00";
            }
        }
Esempio n. 2
0
 public void AddSentenceElement(ISentenceElement element)
 {
     SentenceList.Add(element);
     if (element is Word)
     {
         CountWords++;
     }
 }
        /// <summary>
        /// Handles the ValueChanged event of the SentenceUpDown control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void SentenceUpDown_ValueChanged(object sender, EventArgs e)
        {
            SentenceList s1;        // Holds List of sentences

            try
            {
                s1 = new SentenceList(text);

                String strSentence; //get the sentence and formats the string

                if ((int)this.SentenceUpDown.Value == 0)
                {
                    this.SentenceTextBox.Text = "Choose A Sentence";
                    //Display this when the value for the up down is zero
                }



                this.SentenceUpDown.Maximum = s1.NumberOfSentences; //max sentence limit
                this.SentenceUpDown.Minimum = 0;                    //min sentence limit

                int i = (int)this.SentenceUpDown.Value;             //The current sentence index
                                                                    //corresponding to the up down


                strSentence = s1[i - 1].ToString().Replace("\b", "");   //gets rid of the backspace characters
                strSentence = Regex.Replace(strSentence, @"\s+", " ");  //gets rid of multi space and
                                                                        //replaces with single spaces

                for (int k = 0; k < strSentence.Length; k++)
                {
                    if (strSentence[k] == '.' || strSentence[k] == '!' || strSentence[k] == '?' ||
                        strSentence[k] == ',' || strSentence[k] == ';' || strSentence[k] == '"')
                    {
                        strSentence = strSentence.Remove(k - 1, 1);
                        //takes out the space before the punctuation
                    }
                }



                this.SentenceTextBox.Text = strSentence;  //adds the formated sentence to the text box



                this.SenNumWordsTextBox.Text = $"{s1[i - 1].WordCount}";
                this.SenAveWordsTextBox.Text = $"{s1[i - 1].AverageWordLength}";
                //adds the word count and average word length to the respective text boxes
            }
            catch (Exception)
            {
                if ((int)this.SentenceUpDown.Value != 0)
                {
                    MessageBox.Show("Please choose a text file.");
                }
                // Display message if a the control is activated before the user chooses a text file
            }
        }
Esempio n. 4
0
 public void PublishSentence()
 {
     if (!CurrentSentence.WordList.Any())
     {
         return;
     }
     SentenceList.Add(CurrentSentence);
     CurrentSentence = new Sentence();
     RaisePropertyChanged("CurrentSentenceAsString");
 }
Esempio n. 5
0
        public bool IsQuestionSentences()
        {
            var s = SentenceList.FindLast(x => x is PunctuationSign);

            if (((PunctuationSign)s).IsQuestionMark())
            {
                return(true);
            }
            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// listener for the tool strip file menu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string contents = "";//string to hold text file

            //open a file to work with
            OpenFileDialog OpenDlg = new OpenFileDialog();

            OpenDlg.Filter           = "text files|*.txt;*.text|all files|*.*";
            OpenDlg.InitialDirectory = "Project2/Text Files";
            OpenDlg.Title            = "Select the File you would like to work with.";
            if (OpenDlg.ShowDialog() != DialogResult.Cancel)
            {
                Filename = OpenDlg.FileName;
            }

            //Utilize the file using the Text class
            txt      = new Text(Filename);
            wrd      = new Words(txt);
            sentList = new SentenceList(txt);
            paraList = new ParagraphList(txt);
            int locate     = (int)numericUpDown1.Value; //holds a formatted double for pulling from the SentenceList
            int paraLocate = (int)numericUpDown2.Value; //holds a formatted double for pulling from the ParagraphList

            contents = File.ReadAllText(Filename);

            //fill textBoxes for original text and tokens
            textBox1.Text = contents;
            textBox2.Text = string.Join(Environment.NewLine, txt.GetTokens());

            //fill textBox for distinctWords
            textBox3.Text = string.Join(Environment.NewLine, wrd.GetWords());

            //fill textBoxes for Sentence and Paragraph
            textBox4.Text = sentList.Sentences[locate].FullSentence;
            textBox5.Text = sentList.Sentences[locate].WordCount.ToString();
            string s;
            string t;

            textBox6.Text  = s = string.Format("{0:0.00}", sentList.Sentences[locate].AvgWordLength);
            textBox9.Text  = paraList.Paragraphs[paraLocate].OriginalParagraph;
            textBox8.Text  = paraList.Paragraphs[paraLocate].NumSentences.ToString();
            textBox7.Text  = paraList.Paragraphs[paraLocate].NumWords.ToString();
            textBox10.Text = t = string.Format("{0:0.00}", paraList.Paragraphs[paraLocate].AvgSentenceWordCount);
        }//newToolStripMenuItem_Click(object,EventArgs)
Esempio n. 7
0
    private void Init()
    {
        _greetings = new SentenceList()
        {
            "Behold, people. We have a new contestant",
            "Nice try.*Let's hope the next one endures a little longer.",
            "See this? Another human enters the frame.",
            "Don't fret. We have enough of those champions left.",
            "Well, another human enters the stage*Let's so how long this one fares."
        };

        _roundWon = new SentenceList()
        {
            "Unbelievable. The human has survived the first round.",
            "Who would have thought?*The champion shows perserverance.",
            "Another round goes to the humans.*Maybe they aren't as pathetic as we thought.",
            "Well, well, this was rather easy, wasn't it?",
            "Behold. See and Witness.*A new danger awaits our hero.",
            "Next Round."
        };
    }
Esempio n. 8
0
        public void BreakIntoSentences()
        {
            int column;
            String token;
            String text = OriginalText;
            list = new SentenceList();

            while (!String.IsNullOrEmpty(text))
            {
                column = text.IndexOfAny(SentenceDelimiters.ToCharArray());

                if (column < 0)
                    column = text.Length;

                if (column == 0)
                    column = 1;

                token = text.Substring(0, (++column));
                text = text.Substring(column);
                text = text.Trim(" \t".ToCharArray());
                list.AddToList(token);
            }
        }
        /// <summary>
        /// Handles the Click event of the selectTextFileToolStripMenuItem control.
        /// Allows the user to select a text file
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void selectTextFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Words         w1;                           //for finding the DistinctWords
            SentenceList  s1;                           //for displaying the Sentences
            ParagraphList p1;                           //for displaying the Paragraphs

            #region Selecting the Text
            dlg.Filter           = "text files|*.txt;*.text|all files|*.*";
            dlg.InitialDirectory = @"..\..\TextFile";
            dlg.Title            = "Open Text File";

            if (DialogResult.OK != dlg.ShowDialog())
            {
                MessageBox.Show(null, "No file selected. Going back to menu.",
                                "No File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;         //returns to main menu
            }

            text = new Text(dlg.FileName);

            OriginalTextPrint.Text  = text.TextFile;
            OriginalTextPrint.Text += "\n\n";       //Adding some extra lines
            #endregion


            w1 = new Words(text);
            s1 = new SentenceList(text);
            p1 = new ParagraphList(text);

            #region Displaying the Tokens
            TokensListBox.Items.Clear();        //Clears the text box for new info
            for (int i = 0; i < text.Tokens.Count; i++)
            {
                if (text.Tokens[i] == "\r" || text.Tokens[i] == "\n")
                {
                    TokensListBox.Items.Add(@"\n");
                    //changing the \r and \n to literal \ns for the tokens
                }
                else if (text.Tokens[i] == "\t")
                {
                    TokensListBox.Items.Add(@"\t");
                    //changing \t to literal \t in the tokens
                }
                else
                {
                    TokensListBox.Items.Add(text.Tokens[i]);
                    //Just add non escape characters to the TokensListBox
                }
            }
            #endregion


            #region Displaying the Distinct Words
            w1.DistinctWordList.Sort();     //gets the distinct words for w1 and sorts them
            DistinctWordsBox.Items.Clear(); //Clears the text box for new info

            for (int i = 0; i < w1.Count; i++)
            {
                DistinctWordsBox.Items.Add($"{w1[i].ToString()}");
                //gets each index of the distinctWord object in the from the DistinctWord List
                // in the Words object by an indexer.
            }
            #endregion


            #region Labeling the Status Bar

            iLastIndex  = dlg.FileName.LastIndexOf('\\');         //find last index of \ for file name
            strFileName = dlg.FileName.Substring(iLastIndex + 1); //the file name starts one character
                                                                  //after the \
            this.FileStatusLabel.Text          = $"File: {strFileName.PadRight(95, ' ')}";
            this.TokensStatusLabel.Text        = $"Tokens: {text.Tokens.Count}";
            this.DistinctWordsStatusLabel.Text = $"Distinct Words: {w1.Count}";
            this.SenStatusLabel.Text           = $"Sentences: {s1.NumberOfSentences}";
            this.ParaStripStatusLabel.Text     = $"Paragraphs: {p1.NumberOfParagraphs}";
            //writes info o the labels in the status strip and pads them

            #endregion
        }
Esempio n. 10
0
 public void PublishSentence(string sentence, string sender)
 {
     SentenceList.Add(new Sentence(sentence, sender));
 }
Esempio n. 11
0
        public SentenceList getSentList()
        {
            SentenceList newList = new SentenceList(list);

            return newList;
        }