internal C45FeatureSetCollection GetFSCFromFile(String filename) { C45FeatureSetCollection featureSetCollection = new C45FeatureSetCollection(); C45Schema schema = C45Schema.CreateFromFile(filename.Replace(".data".ToString(), ".names".ToString())); int character = 0; String line = String.Empty; FileStream file = new FileStream( filename, FileMode.Open); while (character >= 0) { line = String.Empty; character = file.ReadByte(); while (character != 0x0A && character > 0) { line += Convert.ToChar(character); character = file.ReadByte(); } featureSetCollection.Add(C45FeatureSet.GetFSFromLine(line, schema)); } return(featureSetCollection); }
private void DisableControls() { this.dataGridView.Rows.Clear(); this.dataGridView.Columns.Clear(); this.schema = null; this.generator = null; this.docImageForm = null; this.openToolStripMenuItem.Enabled = true; this.newRowToolStripMenuItem.Enabled = false; this.loadFSCToolStripMenuItem.Enabled = false; this.removeRowToolStripMenuItem.Enabled = false; this.addallresultcasesToolStripMenuItem.Enabled = false; this.addAllUserResultsToolStripMenuItem.Enabled = false; this.addResultsToolStripMenuItem.Enabled = false; this.classifyToolStripMenuItem.Enabled = false; this.closeToolStripMenuItem.Enabled = false; this.removeRowToolStripMenuItem1.Enabled = false; this.removeRowToolStripMenuItem.Enabled = false; this.saveDebugInfoToolStripMenuItem.Enabled = false; this.clearDebugInfoToolStripMenuItem.Enabled = false; this.viewToolStripMenuItem.Enabled = false; this.extrasToolStripMenuItem.Enabled = false; this.actionToolStripMenuItem1.Enabled = false; this.hRTMapperToolStripMenuItem.Visible = false; this.listBoxStatus.Enabled = true; this.listBoxStatus.Items.Clear(); this.progressBarState.Value = 0; }
internal static C45FeatureSet GetFSFromLine(String line, C45Schema schema) { C45FeatureSet featureSet = new C45FeatureSet(); int currentFeature = 0; String[] features = line.Split(",".ToCharArray()); for (int i = 0; i < features.Length; i++) { features[i] = features[i].Trim(); } foreach (C45SchemaProperty column in schema.Properties) { if (features[currentFeature] == "" || features[currentFeature] == "?") { featureSet.AddUnknownFeature(); } else { if (column.IsDiscrete) { C45DiscreteFeature discreteFeature = new C45DiscreteFeature(); C45DiscreteFeatureAttribute discreteFeatureAttribute = new C45DiscreteFeatureAttribute(); discreteFeatureAttribute.AttributeName = features[currentFeature]; discreteFeatureAttribute.Probability = 100; discreteFeature.Add(discreteFeatureAttribute); featureSet.AddDiscreteFeature(discreteFeature); } else { C45ContinuousFeature continuousFeature = new C45ContinuousFeature(); continuousFeature.LowerBound = Convert.ToInt32(features[currentFeature]); continuousFeature.UpperBound = Convert.ToInt32(features[currentFeature]); featureSet.AddContinousFeature(continuousFeature); } } currentFeature++; } featureSet.UserResult.ClassName = features[currentFeature]; return(featureSet); }
private void CreateColumns() { try { this.schema = C45Schema.CreateFromFile(c45Settings.C45SchemaFilename + @".names"); int index = 0; foreach (C45SchemaProperty property in schema.Properties) { if (property.IsDiscrete) { DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn(); combo.Name = property.Name; combo.HeaderText = property.Name; combo.Items.Add("?".ToString()); foreach (String attribute in property.DiscreteAttributes) { combo.Items.Add(attribute); } this.dataGridView.Columns.Add(combo); } else { DataGridViewTextBoxColumn text = new DataGridViewTextBoxColumn(); text.Name = property.Name; text.HeaderText = property.Name; this.dataGridView.Columns.Add(text); } this.dataGridView.Columns[index].Tag = property; index++; } this.userClassColumn = index++; this.resultClassColumn = index++; this.stateColumn = index; AddClassesToGridView(schema.Classes); AddResultColumn(); } catch (C45Exception ex) { MessageBox.Show(ex.GetString()); CloseToolStripMenuItem_Click(this, new EventArgs()); } }
public C45Schema ParseNamesFile(String filename) { C45Schema schema = new C45Schema(); try { FileStream f = new FileStream(filename, FileMode.Open); StreamReader s = new StreamReader(f); String line = String.Empty; do { line = s.ReadLine(); line = line.TrimStart("\t".ToCharArray()); } while (line == String.Empty || line[0] == '|'); while (!line.Contains(".") && !s.EndOfStream) { line += s.ReadLine(); } line = line.Remove(line.LastIndexOfAny(".".ToCharArray())); String[] values = line.Split(",".ToCharArray()); //Add classes if (values.Length > 0) { foreach (String newClass in values) { String newString = newClass.Trim(); schema.AddClass(newString); } } //Add properties while (!s.EndOfStream) { line = s.ReadLine(); if (line != String.Empty && line[0] != '|') { values = this.FormatLine(line); if (values[1].Contains("continuous")) { schema.Properties.Add(false, values[0], null); } else { //Discrete attribute found String[] discreteAttributes = values[1].Split(",".ToCharArray()); List <String> attributeList = new List <String> (); foreach (String singleAttribute in discreteAttributes) { String attribute = singleAttribute.Trim(); attributeList.Add(attribute); } schema.Properties.Add(true, values[0], attributeList); } } } } catch (Exception e) { throw (new C45Exception(C45Exceptions.PARSE_NAMES_ERROR, e)); } return(schema); }