static void ClassifyFile2(string fileName, int rowNum = -1, int limit = int.MaxValue) { var root = new IndexedNode(null, ""); // Read the file and display it line by line. using (System.IO.StreamReader file = new System.IO.StreamReader(fileName)) { string line; var delims = new char[] { '/', '_', '[', ']' }; while ((line = file.ReadLine()) != null) { string str = line; if (rowNum >= 0) { var defs = line.Split(' '); if (!(rowNum < defs.Length)) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Exception: row number " + rowNum + " is over the number of columns in the entry."); sb.AppendLine("---"); sb.AppendLine(line); sb.AppendLine("---"); throw new Exception(sb.ToString()); } str = defs[rowNum]; } root.AddNode(str.Split(delims)); } } root.ListUp(0, limit); }
internal override void AddNode(IEnumerable <string> strs) { NofDescendants++; if (strs.Count() == 0) { return; } int j; string childNodeStr = strs.First(); if (Int32.TryParse(childNodeStr, out j)) { indices.Add(j); childNodeStr = NumberNodeString; } if (!Children.ContainsKey(childNodeStr)) { Children[childNodeStr] = new IndexedNode(this, childNodeStr); } Children[childNodeStr].AddNode(strs.Skip(1)); }
internal IndexedNode(IndexedNode parent, string word) : base(word) { Parent = parent; }