private void button3_Click(object sender, EventArgs e) { try { OdbcConnection connection = new OdbcConnection(); connection.ConnectionString = "DSN=PostgreSQL35W;UID=masterwordcounter;PWD=masterwordcounter"; connection.Open(); label1.Text = "State: " + connection.State.ToString(); string q = "SELECT id,name,content,author FROM texts"; OdbcCommand getAllTexts = new OdbcCommand(q, connection); OdbcDataReader odr = getAllTexts.ExecuteReader(); lista_teksta.Clear(); while (odr.Read()) { Tekst t = new Tekst(); t.Id = odr.GetInt32(0); t.Sadrzaj = odr.GetString(2); t.Naziv = odr.GetString(1); t.Autor = odr.GetString(3); lista_teksta.Add(t); } comboBox1.DataSource = null; comboBox1.DataSource = lista_teksta; connection.Close(); odr.Close(); } catch (Exception er) { MessageBox.Show(er.Message); } }
private void StatsDashboard_Load(object sender, EventArgs e) { c_analiza.SelectedIndex = 1; c_tip_analize.SelectedIndex = 1; lista_teksta = new List <Tekst>(); lista_stats = new List <Statistika>(); lista_stats_text = new List <Statistika>(); lista_PDF = new List <StatistikaTekst>(); podsuma = 0; OdbcConnection connection = new OdbcConnection(); connection.ConnectionString = "DSN=PostgreSQL35W;UID=masterwordcounter;PWD=masterwordcounter"; connection.Open(); string q = "SELECT id,name,content,author FROM texts"; OdbcCommand getAllTexts = new OdbcCommand(q, connection); OdbcDataReader odr = getAllTexts.ExecuteReader(); lista_teksta.Clear(); while (odr.Read()) { Tekst t = new Tekst(); t.Id = odr.GetInt32(0); t.Sadrzaj = odr.GetString(2); t.Naziv = odr.GetString(1); t.Autor = odr.GetString(3); lista_teksta.Add(t); } c_tekst.DataSource = null; c_tekst.DataSource = lista_teksta; connection.Close(); odr.Close(); }
private void button2_Click(object sender, EventArgs e) { Tekst t = (Tekst)(comboBox1.SelectedItem); TextResult tr = new TextResult(lista_rijeci, t.Naziv, t); tr.Show(); }
public TextResult(MySortableBindingList<Rijec> lr, string n, Tekst t) { naziv = n; lista_rijeci = lr; lista_rijeci_gramatika = new MySortableBindingList<Rijec>(); lista_rijeci_poslije_gramatike = new MySortableBindingList<Rijec>(); Gramatika = false; tekst = t; InitializeComponent(); }
public TextResult(MySortableBindingList <Rijec> lr, string n, Tekst t) { naziv = n; lista_rijeci = lr; lista_rijeci_gramatika = new MySortableBindingList <Rijec>(); lista_rijeci_poslije_gramatike = new MySortableBindingList <Rijec>(); Gramatika = false; tekst = t; InitializeComponent(); }
private void button2_Click(object sender, EventArgs e) { string linija = ""; try { using (StreamReader sr = new StreamReader(openFileDialog1.FileName)) { linija = sr.ReadToEnd(); Tekst t = new Tekst(); t.Sadrzaj = linija; t.Naziv = textBox2.Text; t.Autor = textBox3.Text; MessageBox.Show("Tekst unesen!"); lista_tekstova.Add(t); } } catch (Exception ex) { Console.WriteLine("The file could not be read:"); Console.WriteLine(ex.Message); } }
private void calculateStats(String type_of_text_amount, int type_of_stats) { try { if (type_of_text_amount.Equals("Svi tekstovi")) { int broj_rez = (int)(numericUpDown1.Value); try { OdbcConnection connection = new OdbcConnection(); connection.ConnectionString = "DSN=PostgreSQL35W;UID=masterwordcounter;PWD=masterwordcounter"; connection.Open(); string q = "SELECT * FROM (SELECT sum(num_of_repeats) prosjek, avg(pct_of_occurence), word_text FROM stats GROUP BY word_text ORDER BY prosjek DESC) top_sve LIMIT ? OFFSET 0"; OdbcCommand getAllTexts = new OdbcCommand(q, connection); getAllTexts.Parameters.Add("@OFFSET", OdbcType.Int).Value = broj_rez; OdbcDataReader odr = getAllTexts.ExecuteReader(); int a = 0; lista_stats.Clear(); while (odr.Read()) { a++; Statistika s = new Statistika(); s.Broj_ponavljanja = odr.GetInt32(0); s.Procenat_pojave_unutar_teksta = odr.GetDecimal(1) * 100; s.Id = a; s.Rijec_tekst = odr.GetString(2); lista_stats.Add(s); } dataGridView1.DataSource = null; dataGridView1.DataSource = lista_stats; connection.Close(); dataGridView1.Columns["Rijec_id"].Visible = false; dataGridView1.Columns["Tekst_id"].Visible = false; dataGridView1.Columns["Tip_statistike"].Visible = false; dataGridView1.Columns["Rank_unutar_teksta"].Visible = false; chart1.Series["Rijec"].Points.Clear(); for (int i = 0; i < lista_stats.Count; i++) { chart1.Series["Rijec"].Points.AddXY(i + 1, lista_stats[i].Broj_ponavljanja); } chart1.ChartAreas[0].AxisX.Maximum = broj_rez; chart1.ChartAreas[0].AxisX.Minimum = 0; chart1.ChartAreas[0].AxisY.Maximum = Convert.ToDouble(lista_stats[0].Broj_ponavljanja); chart1.ChartAreas[0].AxisY.Minimum = 0; chart2.Series["Rijec"].Points.Clear(); chart2.Series["LinearPlot"].Points.Clear(); for (int i = 0; i < lista_stats.Count; i++) { chart2.Series["Rijec"].Points.AddXY(Math.Log10(i + 1), Math.Log10(lista_stats[i].Broj_ponavljanja)); chart2.Series["LinearPlot"].Points.AddXY(Math.Log10(i + 1), Math.Log10(lista_stats[0].Broj_ponavljanja / (i + 1))); } chart2.ChartAreas[0].AxisX.Maximum = Math.Log10(broj_rez); chart2.ChartAreas[0].AxisX.Minimum = 0; chart2.ChartAreas[0].AxisY.Maximum = Convert.ToDouble(Math.Log10(lista_stats[0].Broj_ponavljanja)); chart2.ChartAreas[0].AxisY.Minimum = Math.Log10(lista_stats[lista_stats.Count - 1].Broj_ponavljanja); odr.Close(); } catch (Exception es) { MessageBox.Show(es.Message); } } if (type_of_text_amount.Equals("Pojedinačan tekst")) { Tekst trenutni_tekst = (Tekst)(c_tekst.SelectedItem); int broj_rez = (int)(numericUpDown1.Value); try { OdbcConnection connection = new OdbcConnection(); connection.ConnectionString = "DSN=PostgreSQL35W;UID=masterwordcounter;PWD=masterwordcounter"; connection.Open(); string q = "SELECT * FROM (SELECT sum(num_of_repeats) prosjek, avg(pct_of_occurence), word_text FROM stats WHERE text_id = ? AND type_of_stats = ? GROUP BY word_text ORDER BY prosjek DESC) top_sve LIMIT ? OFFSET 0"; OdbcCommand getAllTexts = new OdbcCommand(q, connection); getAllTexts.Parameters.Add("@text_id", OdbcType.Int).Value = trenutni_tekst.Id; getAllTexts.Parameters.Add("@type_of_stats", OdbcType.Int).Value = type_of_stats; getAllTexts.Parameters.Add("@OFFSET", OdbcType.Int).Value = broj_rez; OdbcDataReader odr = getAllTexts.ExecuteReader(); int a = 0; podsuma = 0; lista_stats.Clear(); while (odr.Read()) { a++; Statistika s = new Statistika(); s.Broj_ponavljanja = odr.GetInt32(0); s.Procenat_pojave_unutar_teksta = odr.GetDecimal(1) * 100; s.Id = a; s.Rijec_tekst = odr.GetString(2); lista_stats.Add(s); podsuma += s.Broj_ponavljanja; } dataGridView1.DataSource = null; dataGridView1.DataSource = lista_stats; connection.Close(); dataGridView1.Columns["Rijec_id"].Visible = false; dataGridView1.Columns["Tekst_id"].Visible = false; dataGridView1.Columns["Tip_statistike"].Visible = false; dataGridView1.Columns["Rank_unutar_teksta"].Visible = false; odr.Close(); chart1.Series["Rijec"].Points.Clear(); for (int i = 0; i < lista_stats.Count; i++) { chart1.Series["Rijec"].Points.AddXY(i + 1, lista_stats[i].Broj_ponavljanja); } chart1.ChartAreas[0].AxisX.Maximum = broj_rez; chart1.ChartAreas[0].AxisX.Minimum = 0; chart1.ChartAreas[0].AxisY.Maximum = Convert.ToDouble(lista_stats[0].Broj_ponavljanja); chart1.ChartAreas[0].AxisY.Minimum = 0; chart2.Series["Rijec"].Points.Clear(); chart2.Series["LinearPlot"].Points.Clear(); for (int i = 0; i < lista_stats.Count; i++) { chart2.Series["Rijec"].Points.AddXY(Math.Log10(i + 1), Math.Log10(lista_stats[i].Broj_ponavljanja)); chart2.Series["LinearPlot"].Points.AddXY(Math.Log10(i + 1), Math.Log10(lista_stats[0].Broj_ponavljanja / (i + 1))); } chart2.ChartAreas[0].AxisX.Maximum = Math.Log10(broj_rez); chart2.ChartAreas[0].AxisX.Minimum = 0; chart2.ChartAreas[0].AxisY.Maximum = Convert.ToDouble(Math.Log10(lista_stats[0].Broj_ponavljanja)); chart2.ChartAreas[0].AxisY.Minimum = Math.Log10(lista_stats[lista_stats.Count - 1].Broj_ponavljanja); } catch (Exception es) { MessageBox.Show(es.Message); } } saveTextStatsToolStripMenuItem.PerformClick(); } catch (Exception es2) { MessageBox.Show(es2.Message); } }
private void saveTextStatsToolStripMenuItem_Click(object sender, EventArgs e) { Tekst trenutni_tekst = (Tekst)(c_tekst.SelectedItem); try { OdbcConnection connection = new OdbcConnection(); connection.ConnectionString = "DSN=PostgreSQL35W;UID=masterwordcounter;PWD=masterwordcounter"; connection.Open(); string q = "SELECT * FROM (SELECT sum(num_of_repeats) prosjek, avg(pct_of_occurence), word_text FROM stats WHERE text_id = ? AND type_of_stats = ? GROUP BY word_text ORDER BY prosjek DESC) top_sve"; OdbcCommand getAllTexts = new OdbcCommand(q, connection); getAllTexts.Parameters.Add("@text_id", OdbcType.Int).Value = trenutni_tekst.Id; getAllTexts.Parameters.Add("@type_of_stats", OdbcType.Int).Value = c_analiza.SelectedIndex + 1; OdbcDataReader odr = getAllTexts.ExecuteReader(); int a = 0; lista_stats_text.Clear(); double ukupno = 0; while (odr.Read()) { a++; Statistika s = new Statistika(); s.Broj_ponavljanja = odr.GetInt32(0); s.Procenat_pojave_unutar_teksta = odr.GetDecimal(1) * 100; s.Id = a; s.Rijec_tekst = odr.GetString(2); lista_stats_text.Add(s); ukupno += s.Broj_ponavljanja; } odr.Close(); List <koordinate> pravi_rez = new List <koordinate>(); List <koordinate> ideal_rez = new List <koordinate>(); double suma_razlike = 0; for (int i = 0; i < lista_stats_text.Count; i++) { if (double.IsNegativeInfinity(Math.Log10(lista_stats_text[i].Broj_ponavljanja))) { break; } if (double.IsNegativeInfinity(Math.Log10(lista_stats_text[0].Broj_ponavljanja / (i + 1)))) { break; } koordinate k = new koordinate(); k.X = Math.Log10(i + 1); k.Y = Math.Log10(lista_stats_text[i].Broj_ponavljanja); pravi_rez.Add(k); koordinate k1 = new koordinate(); k1.X = Math.Log10(i + 1); k1.Y = Math.Log10(lista_stats_text[0].Broj_ponavljanja / (i + 1)); ideal_rez.Add(k1); } try { for (int i = 0; i < pravi_rez.Count; i++) { double a1 = Math.Round(Math.Pow((pravi_rez[i].X - ideal_rez[i].X), 2) + Math.Pow((pravi_rez[i].Y - ideal_rez[i].Y), 2), 4); suma_razlike += a1; suma_razlike = Math.Round(suma_razlike, 4); } } catch (ArithmeticException ae) { MessageBox.Show(ae.Message); } double MSE = suma_razlike / pravi_rez.Count; double[] lista_x = new double[ideal_rez.Count]; double[] lista_y = new double[ideal_rez.Count]; int j = 0; foreach (koordinate k in pravi_rez) { lista_x[j] = k.X; lista_y[j] = k.Y; j++; } double[] f = Fit.Polynomial(lista_x, lista_y, 2, MathNet.Numerics.LinearRegression.DirectRegressionMethod.NormalEquations); var bestfit = Tuple.Create(0.0, 0.0); bestfit = Fit.Line(lista_x, lista_y); l_text_stats.Text = "Date riječi u tabeli predstavljaju " + Math.Round((double)(podsuma / ukupno) * 100, 2) + "% od cijelog teksta. Ukupno posebnih riječi ima " + lista_stats_text.Count + " a cijeli tekst ima " + ukupno + " riječi."; l_nastavak.Text = "Suma odstupanja od idealnog Zipfovog zakona je " + suma_razlike + ", MSE je " + Math.Round(MSE, 5) + ", RMSE je " + Math.Round(Math.Sqrt(MSE), 5) + ". Best-fit polinom za rezultate je y(x) = " + Math.Round(f[1], 2) + "X + " + Math.Round(f[2], 2) + "X ^ 2 + " + Math.Round(f[0], 2); if (c_analiza.SelectedIndex == 0) { MSENDPF = Math.Round(MSE, 5); } else { MSEGPDF = Math.Round(MSE, 5); } if (MSENDPF != 0.0 && MSEGPDF != 0.0) { StatistikaTekst st = new StatistikaTekst(); st.Ime_teksta = c_tekst.SelectedItem.ToString(); st.RMSE_G1 = MSEGPDF; st.RMSE_N1 = MSENDPF; double h = Math.Round(st.RMSE_N1 - st.RMSE_G1, 5); st.Pct_diff = Math.Round(h / st.RMSE_N1, 5); if (st.Pct_diff > 1) { st.Pct_diff = st.Pct_diff - 1; } lista_PDF.Add(st); MSEGPDF = 0.0; MSENDPF = 0.0; } } catch (Exception es) { MessageBox.Show(es.Message); } }
private void StatsDashboard_Load(object sender, EventArgs e) { c_analiza.SelectedIndex = 1; c_tip_analize.SelectedIndex = 1; lista_teksta = new List<Tekst>(); lista_stats = new List<Statistika>(); lista_stats_text = new List<Statistika>(); lista_PDF = new List<StatistikaTekst>(); podsuma = 0; OdbcConnection connection = new OdbcConnection(); connection.ConnectionString = "DSN=PostgreSQL35W;UID=masterwordcounter;PWD=masterwordcounter"; connection.Open(); string q = "SELECT id,name,content,author FROM texts"; OdbcCommand getAllTexts = new OdbcCommand(q, connection); OdbcDataReader odr = getAllTexts.ExecuteReader(); lista_teksta.Clear(); while (odr.Read()) { Tekst t = new Tekst(); t.Id = odr.GetInt32(0); t.Sadrzaj = odr.GetString(2); t.Naziv = odr.GetString(1); t.Autor = odr.GetString(3); lista_teksta.Add(t); } c_tekst.DataSource = null; c_tekst.DataSource = lista_teksta; connection.Close(); odr.Close(); }
private void button3_Click(object sender, EventArgs e) { try { OdbcConnection connection = new OdbcConnection(); connection.ConnectionString = "DSN=PostgreSQL35W;UID=masterwordcounter;PWD=masterwordcounter"; connection.Open(); label1.Text= "State: " + connection.State.ToString(); string q = "SELECT id,name,content,author FROM texts"; OdbcCommand getAllTexts = new OdbcCommand(q,connection); OdbcDataReader odr = getAllTexts.ExecuteReader(); lista_teksta.Clear(); while(odr.Read()) { Tekst t = new Tekst(); t.Id = odr.GetInt32(0); t.Sadrzaj = odr.GetString(2); t.Naziv = odr.GetString(1); t.Autor = odr.GetString(3); lista_teksta.Add(t); } comboBox1.DataSource = null; comboBox1.DataSource = lista_teksta; connection.Close(); odr.Close(); } catch(Exception er) { MessageBox.Show(er.Message); } }