static void buildPinYinIndex() { var index = 0x4e00; List <HashSet <int> > t = new List <HashSet <int> >(); while (index <= 0x9fa5) { var ch = (char)index; HashSet <int> ls = new HashSet <int>(); var p1 = getPinYin(ch); if (p1 >= 0) { ls.Add(p1); } getPinYin2(ch, ls); if (ls.Count == 0) { char c; Dict.TraditionalToSimplified(ch, out c); getPinYin2(c, ls); } if (ls.Count == 0) { var py3 = GetPyName2(ch.ToString()); if (py3 > 0) { ls.Add(py3); } if (ch == '刓') { ls.Add(GetPyName("Liang")); } } if (ls.Count == 0) { getPinYin3(ch, ls); } t.Add(ls); index++; } index = 0; List <short> node = new List <short>(); //StringBuilder node = new StringBuilder(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < t.Count; i++) { var item = t[i]; //node.Append(","); if (item.Count == 0) { node.Add(-1); } else { node.Add((short)index); index += item.Count; foreach (var pyNum in item) { sb.Append(","); sb.Append(pyNum); } } } //index++; node.Add((short)index); for (int i = node.Count - 1; i >= 0; i--) { if (node[i] == -1) { node[i] = node[i + 1]; } } File.WriteAllText("pyIndex.txt", string.Join(",", node)); sb.Remove(0, 1); File.WriteAllText("pyData.txt", sb.ToString()); }
static void buildPinYinIndex(int start, int end, string outIndexFile, string outDataFile) { var index = start; List <HashSet <int> > t = new List <HashSet <int> >(); while (index <= end) { var ch = (char)index; HashSet <int> ls = new HashSet <int>(); var p1 = getPinYin(ch);//此方法查找最常用的拼音, 此处可能会出错, 出错字符如 芃 HashSet <int> ls2 = new HashSet <int>(); getPinYin2(ch, ls2); if (ls2.Count > 0) { if (ls2.Contains(p1)) { ls.Add(p1); } foreach (var item in ls2) { ls.Add(item); } } if (ls.Count == 0) { char c; Dict.TraditionalToSimplified(ch, out c); getPinYin2(c, ls); } if (ls.Count == 0) { var py3 = GetPyName2(ch.ToString()); if (py3 > 0) { ls.Add(py3); } if (ch == '刓') { ls.Add(GetPyName("Liang")); } } if (ls.Count == 0) { getPinYin3(ch, ls); } t.Add(ls); index++; } index = 0; List <short> node = new List <short>(); //StringBuilder node = new StringBuilder(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < t.Count; i++) { var item = t[i]; //node.Append(","); if (item.Count == 0) { node.Add(-1); } else { node.Add((short)index); index += item.Count; foreach (var pyNum in item) { sb.Append(","); sb.Append(pyNum); } } } //index++; node.Add((short)index); for (int i = node.Count - 1; i >= 0; i--) { if (node[i] == -1) { node[i] = node[i + 1]; } } File.WriteAllText(outIndexFile, string.Join(",", node)); sb.Remove(0, 1); File.WriteAllText(outDataFile, sb.ToString()); }