/// <summary> /// 文件总行数 /// </summary> /// <param name="file"></param> /// <returns></returns> static int load(string[] buffers, Dictionary<char, CharNode> dic) { if (buffers == null) return 0; int n = 0; string[] w = null; CharNode cn = null; foreach (string line in buffers) { if (string.IsNullOrEmpty(line)) continue; if (line.StartsWith("#")) continue; cn = new CharNode(); w = line.Split(' '); if (w.Length == 2) { try { //字频计算出自由度 cn.Freq = (int)(Math.Log(Int32.Parse(w[1])) * 100); } catch { } } if (!dic.ContainsKey(w[0][0])) { dic.Add(w[0][0], cn); } else dic[w[0][0]] = cn; ++n; } return n; }
static int WordsLoading(string[] buffers, Dictionary<char, CharNode> dic) { CharNode cn = null; int count = 0; foreach (string line in buffers) { if(line.Length < 2) continue; cn = null; if (dic.ContainsKey(line[0])) cn = dic[line[0]]; if (cn == null) { cn = new CharNode(); dic.Add(line[0], cn); } ++count; cn.AddWordTail(tail(line)); } return count; }
Dictionary<char,object> loadUnit(FileInfo path) { string[] lines = null; if (path.Exists) { lines = File.ReadAllLines(path.FullName); addLastTime(path); } else { lines = getLinesFromResources("units.dic"); } Dictionary<char, object> unit = new Dictionary<char, object>(); long s = now; int lineNum = 0; foreach (string line in lines) { if (line.Length != 1) continue; if (!unit.ContainsKey(line[0])) unit.Add(line[0], typeof(Dictionary)); ++lineNum; } Log.Info("unit loaded time={0}ms,line={1},on file={2}", now - s, lineNum, path); return unit; }