/// <summary> /// event handler for the decrementation of pararaphs /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button4_Click(object sender, EventArgs e) { //decrementation by button if (numericUpDown2.Value > 0) { numericUpDown2.Value--; } else { numericUpDown2.Value = 0; } paraList = new ParagraphList(txt); int paraLocate = (int)numericUpDown2.Value;; if (paraLocate > -1 && paraLocate < paraList.Paragraphs.Count - 1) { string t; 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); } else { textBox9.Text = "There isn't anymore sentences to be displayed."; textBox8.Text = "0"; textBox7.Text = "0"; textBox10.Text = "0.00"; } }
/// <summary> /// Handles the ValueChanged event of the ParagraphUpDown 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 ParagraphUpDown_ValueChanged(object sender, EventArgs e) { ParagraphList p1; // Used to get the paragraphs from the text try { p1 = new ParagraphList(text); String strParagraph; //get the paragraph and formats the string if ((int)this.ParagraphUpDown.Value == 0) { this.ParagraphTextBox.Text = "Choose a Paragraph"; } this.ParagraphUpDown.Maximum = p1.NumberOfParagraphs; //max number of paragraphs this.ParagraphUpDown.Minimum = 0; //min number of paragraphs int i = (int)this.ParagraphUpDown.Value; //index of current paragraph strParagraph = p1[i - 1].ToString().Replace("\b", ""); //gets rid of the backspace characters strParagraph = Regex.Replace(strParagraph, @"\s+", " "); //gets rid of multi space and //replaces with single spaces for (int k = 0; k < strParagraph.Length; k++) { if (strParagraph[k] == '.' || strParagraph[k] == '!' || strParagraph[k] == '?' || strParagraph[k] == ',' || strParagraph[k] == ';' || strParagraph[k] == '"') { strParagraph = strParagraph.Remove(k - 1, 1); //takes out the space before the punctuation } } this.ParagraphTextBox.Text = strParagraph; this.ParaSenNumTextBox.Text = $"{p1[i - 1].SentenceNum}"; this.ParaWordsNumTextBox.Text = $"{p1[i-1].WordNum}"; this.ParaAveWordsTextBox.Text = $"{p1[i-1].AverageWordsPerSentence}"; } catch (Exception) { if ((int)this.ParagraphUpDown.Value != 0) { MessageBox.Show("Please choose a text file."); } //Displays message if user has not chosen a text file yet } }
/// <summary> /// 解析処理 /// </summary> /// <param name="text">テキスト</param> public void Analyze(string text) { ParagraphList.Clear(); var strParagraphList = ParagraphLogic.SplitParagraph(text); foreach (var strParagraph in strParagraphList) { ParagraphList.Add(new ParagraphData(strParagraph)); } TokenList = WordLogic.GetTokenList(text); TokenTbl = WordLogic.GetBasicTokenTbl(text); TokenTypeTbl = WordLogic.GetTokenTypeTbl(TokenList); InfoRate = AnalyzeLogic.CalcInfoRate(TokenList); }
/// <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)
/// <summary> /// event handler for numeric updown of paragraphs /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void numericUpDown2_ValueChanged(object sender, EventArgs e) { paraList = new ParagraphList(txt); int paraLocate = (int)numericUpDown2.Value;; if (paraLocate > -1 && paraLocate < paraList.Paragraphs.Count) { string t; 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); } else { textBox9.Text = "There isn't anymore sentences to be displayed."; textBox8.Text = "0"; textBox7.Text = "0"; textBox6.Text = "0.00"; } }
public List <ParagraphList> GetParagraphs(string cs) { using var con = new MySqlConnection(cs); con.Open(); string sql = "CALL spGetParagraphs"; using var cmd = new MySqlCommand(sql, con); IList <ParagraphList> wsl = new List <ParagraphList>(); var reader = cmd.ExecuteReader(); while (reader.Read()) { var ws = new ParagraphList(); ws.ParagraphID = reader.GetInt32("ParagraphID"); ws.Header = reader.GetString("Header"); ws.Body = reader.GetString("Body"); wsl.Add(ws); } reader.Close(); return((List <ParagraphList>)wsl); }
/// <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 }
public AcceptParagraph(ParagraphList pList) { this.pList = pList; }
public override SyntaxNode Accept(CompleteParagraph p) { p.parentStack.Pop (); var pList = new ParagraphList (this.p); pList.Add (p); p.parentStack.Push (pList); return pList; }