public Pinyin(string fn) { // Syllables for interpreting query using (StreamReader sr = new StreamReader(fn)) { string line; while ((line = sr.ReadLine()) != null) { if (line == string.Empty) { continue; } string[] parts = line.Split(new char[] { '\t' }); PinyinParseSyllable ps = new PinyinParseSyllable(parts[0], parts[1] == "v"); syllList.Add(ps); surfToNum[parts[1]] = parts[0]; surfToNum[parts[2]] = parts[0] + '1'; surfToNum[parts[3]] = parts[0] + '2'; surfToNum[parts[4]] = parts[0] + '3'; surfToNum[parts[5]] = parts[0] + '4'; numToSurf[parts[0]] = parts[1]; numToSurf[parts[0] + '1'] = parts[2]; numToSurf[parts[0] + '2'] = parts[3]; numToSurf[parts[0] + '3'] = parts[4]; numToSurf[parts[0] + '4'] = parts[5]; } } surfToNum["r"] = "r"; numToSurf["r"] = "r"; syllList.Sort((a, b) => b.Text.Length.CompareTo(a.Text.Length)); }
public Pinyin() { // Syllable-to-ID int maxId = 0; Assembly a = typeof(DB).GetTypeInfo().Assembly; string fileName = "ZDO.CHSite.files.other.std-pinyin.txt"; using (Stream s = a.GetManifestResourceStream(fileName)) using (StreamReader sr = new StreamReader(s)) { string line; while ((line = sr.ReadLine()) != null) { string[] parts = line.Split('\t'); if (parts.Length != 2) { continue; } int id = int.Parse(parts[0]); if (id > maxId) { maxId = id; } pyToId[parts[1]] = id; } } this.maxId = maxId; // Syllables for interpreting query using (Stream s = a.GetManifestResourceStream("ZDO.CHSite.files.other.syllabary-pinyin.txt")) using (StreamReader sr = new StreamReader(s)) { string line; while ((line = sr.ReadLine()) != null) { if (line == string.Empty) { continue; } string[] parts = line.Split(new char[] { '\t' }); PinyinParseSyllable ps = new PinyinParseSyllable(parts[0], parts[1] == "v"); syllList.Add(ps); } } }
/// <summary> /// Loads known pinyin syllables from embedded resource. /// </summary> private static void loadSyllabary() { Assembly a = Assembly.GetExecutingAssembly(); using (Stream s = a.GetManifestResourceStream("ZD.CedictEngine.Resources.pinyin.txt")) using (StreamReader sr = new StreamReader(s)) { string line; while ((line = sr.ReadLine()) != null) { if (line == string.Empty) { continue; } string[] parts = line.Split(new char[] { '\t' }); PinyinParseSyllable ps = new PinyinParseSyllable(parts[0], parts[1] == "v"); syllList.Add(ps); } } }
/// <summary> /// Loads known pinyin syllables from embedded resource. /// </summary> private static void loadSyllabary() { Assembly a = Assembly.GetExecutingAssembly(); using (Stream s = a.GetManifestResourceStream("ZD.CedictEngine.Resources.pinyin.txt")) using (StreamReader sr = new StreamReader(s)) { string line; while ((line = sr.ReadLine()) != null) { if (line == string.Empty) continue; string[] parts = line.Split(new char[] { '\t' }); PinyinParseSyllable ps = new PinyinParseSyllable(parts[0], parts[1] == "v"); syllList.Add(ps); } } }