public void SetConfiguration(string config_path) { _config = DataPointConfiguration.LoadFromFile(config_path); _columnMapping = new Dictionary <string, DataColumn>(); foreach (var column in _config._types) { //TODO get rid of this switch... push it into the data column as a static factory or such DataColumn dc = null; switch (column.Value) { case DataColumn.DataValueTypes.NUMBER: dc = new DoubleDataColumn(); break; case DataColumn.DataValueTypes.CATEGORY: dc = new CategoryDataColumn(); break; case DataColumn.DataValueTypes.ID: break; case DataColumn.DataValueTypes.CLASS: _hasClasses = true; break; default: throw new ArgumentOutOfRangeException(); } if (dc != null) { dc._header = column.Key; _columns.Add(dc); _columnMapping.Add(dc._header, dc); } } //at this point, the columns exists, go ahead and load the codebook values //TODO really need to generalize this file name and take an input using (StreamReader sr = new StreamReader("codebook.txt")) { while (!sr.EndOfStream) { //TODO move all of this code to the Codebook where it belongs var line = sr.ReadLine(); var parts = line.Split('|'); string header = parts[0]; string data = parts[1]; var col = _columnMapping[header] as CategoryDataColumn; col._codebook.PopulateFromString(data); } } }
public void OutputCodebooks() { using (StreamWriter sw = new StreamWriter("codebook.txt")) { //output header, delim and codebook order foreach (var column in _columns) { CategoryDataColumn col = column as CategoryDataColumn; if (col != null) { sw.WriteLine("{0}|{1}", col._header, col._codebook); } } } }