private void openEmissions_Click(object sender, EventArgs e) { // Set filter options and filter index. openFileDialog.FileName = ""; openFileDialog.Filter = "Emission Files (.emit)|*.emit|All Files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.Multiselect = false; // Call the ShowDialog method to show the dialog box. if (openFileDialog.ShowDialog() == DialogResult.OK) { string line; B = new MySparse2DMatrix(); emissionsSymbols = new Id2Str(); var separator = '\t'; System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog.FileName); emissionsRichTextBox.Text = ""; if ((line = sr.ReadLine()) != null) { if (line.Split(separator).Length == 1) { separator = ' '; } sr.DiscardBufferedData(); sr.BaseStream.Seek(0, System.IO.SeekOrigin.Begin); sr.BaseStream.Position = 0; } while ((line = sr.ReadLine()) != null) { emissionsRichTextBox.Text += line + "\n"; string[] stateValue = line.Split(separator); if (stateValue.Length == 3) { int row = stateSymbols.setId(stateValue[0]); int col = emissionsSymbols.setId(stateValue[1]); B.setValue(row, col, Double.Parse(stateValue[2], CultureInfo.InvariantCulture)); } } sr.Close(); if (B.Count > 0) { buttonCreateHMM.Enabled = true; openObservationsToolStripMenuItem.Enabled = true; } else { buttonCreateHMM.Enabled = false; openObservationsToolStripMenuItem.Enabled = false; MessageBox.Show("Error! Parsed emissions matrix resulted empty. Check your input file please.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void openTransition_Click(object sender, EventArgs e) { // Set filter options and filter index. openFileDialog.FileName = ""; openFileDialog.Filter = "Transition Files (.trans)|*.trans|All Files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.Multiselect = false; // Call the ShowDialog method to show the dialog box. if (openFileDialog.ShowDialog() == DialogResult.OK) { var firstLine = true; string line, firstState = "INIT"; A = new MySparse2DMatrix(); Pi = new List<double>(); piSymbols = new List<string>(); stateSymbols = new Id2Str(); System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog.FileName); transitionsRichTextBox.Text = ""; while ((line = sr.ReadLine()) != null) { transitionsRichTextBox.Text += line + "\n"; if (firstLine) { firstState = line; firstLine = false; } else { string[] stateValue = line.Split('\t'); if (stateValue.Length == 3) { if (stateValue[0] == firstState) { stateSymbols.setId(stateValue[1]); piSymbols.Add(stateValue[1]); Pi.Add(Double.Parse(stateValue[2], CultureInfo.InvariantCulture)); } else { int row = stateSymbols.setId(stateValue[0]); int col = stateSymbols.setId(stateValue[1]); A.setValue(row, col, Double.Parse(stateValue[2], CultureInfo.InvariantCulture)); // Still need to add states to pi with probability 0 if (!piSymbols.Contains(stateValue[0])) { piSymbols.Add(stateValue[0]); Pi.Add(0.0); } if (!piSymbols.Contains(stateValue[1])) { piSymbols.Add(stateValue[1]); Pi.Add(0.0); } } } } } sr.Close(); if (A.Count > 0) { buttonOpenEmissions.Enabled = true; openEmissionsToolStripMenuItem.Enabled = true; } else { buttonOpenEmissions.Enabled = false; openEmissionsToolStripMenuItem.Enabled = false; MessageBox.Show("Error! Parsed transitions matrix resulted empty. Check your input file please.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void openEmissions_Click(object sender, EventArgs e) { // Set filter options and filter index. openFileDialog.FileName = ""; openFileDialog.Filter = "Emission Files (.emit)|*.emit|All Files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.Multiselect = false; // Call the ShowDialog method to show the dialog box. if (openFileDialog.ShowDialog() == DialogResult.OK) { string line; B = new MySparse2DMatrix(); emissionsSymbols = new Id2Str(); var separator = '\t'; System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog.FileName); emissionsRichTextBox.Text = ""; if ((line = sr.ReadLine()) != null) { if (line.Split(separator).Length == 1) separator = ' '; sr.DiscardBufferedData(); sr.BaseStream.Seek(0, System.IO.SeekOrigin.Begin); sr.BaseStream.Position = 0; } while ((line = sr.ReadLine()) != null) { emissionsRichTextBox.Text += line + "\n"; string[] stateValue = line.Split(separator); if (stateValue.Length == 3) { int row = stateSymbols.setId(stateValue[0]); int col = emissionsSymbols.setId(stateValue[1]); B.setValue(row, col, Double.Parse(stateValue[2], CultureInfo.InvariantCulture)); } } sr.Close(); if (B.Count > 0) { buttonCreateHMM.Enabled = true; openObservationsToolStripMenuItem.Enabled = true; } else { buttonCreateHMM.Enabled = false; openObservationsToolStripMenuItem.Enabled = false; MessageBox.Show("Error! Parsed emissions matrix resulted empty. Check your input file please.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void openTransition_Click(object sender, EventArgs e) { // Set filter options and filter index. openFileDialog.FileName = ""; openFileDialog.Filter = "Transition Files (.trans)|*.trans|All Files (*.*)|*.*"; openFileDialog.FilterIndex = 1; openFileDialog.Multiselect = false; // Call the ShowDialog method to show the dialog box. if (openFileDialog.ShowDialog() == DialogResult.OK) { var firstLine = true; string line, firstState = "INIT"; A = new MySparse2DMatrix(); Pi = new List <double>(); piSymbols = new List <string>(); stateSymbols = new Id2Str(); System.IO.StreamReader sr = new System.IO.StreamReader(openFileDialog.FileName); transitionsRichTextBox.Text = ""; while ((line = sr.ReadLine()) != null) { transitionsRichTextBox.Text += line + "\n"; if (firstLine) { firstState = line; firstLine = false; } else { string[] stateValue = line.Split('\t'); if (stateValue.Length == 3) { if (stateValue[0] == firstState) { stateSymbols.setId(stateValue[1]); piSymbols.Add(stateValue[1]); Pi.Add(Double.Parse(stateValue[2], CultureInfo.InvariantCulture)); } else { int row = stateSymbols.setId(stateValue[0]); int col = stateSymbols.setId(stateValue[1]); A.setValue(row, col, Double.Parse(stateValue[2], CultureInfo.InvariantCulture)); // Still need to add states to pi with probability 0 if (!piSymbols.Contains(stateValue[0])) { piSymbols.Add(stateValue[0]); Pi.Add(0.0); } if (!piSymbols.Contains(stateValue[1])) { piSymbols.Add(stateValue[1]); Pi.Add(0.0); } } } } } sr.Close(); if (A.Count > 0) { buttonOpenEmissions.Enabled = true; openEmissionsToolStripMenuItem.Enabled = true; } else { buttonOpenEmissions.Enabled = false; openEmissionsToolStripMenuItem.Enabled = false; MessageBox.Show("Error! Parsed transitions matrix resulted empty. Check your input file please.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }