public string Generate() { var sb = new StringBuilder(); var levelGroups = new[] { ChineseNumber.UpperLevels, ChineseNumber.LowerLevels }; var nums = new int[9].Let(i => i + 1); var total = 0; foreach (var levels in levelGroups.AsKvPairs()) { foreach (var level in levels.Value.AsKvPairs()) { foreach (var num in nums) { var snumber = levels.Key == 0 ? ChineseNumber.GetString(num, x => x.Upper = true) : ChineseNumber.GetString(num); var str = $"{snumber}{level.Value}"; var simplified = ChineseConverter.ToSimplified(str); var traditional = ChineseConverter.ToTraditional(str); var chineseWord = new ChineseWord { Simplified = simplified, Traditional = traditional, SimplifiedPinyin = Pinyin.GetString(ChineseType.Simplified, simplified), TraditionalPinyin = Pinyin.GetString(ChineseType.Traditional, traditional), Tag = num * Math.Pow(10, level.Key), }; var line = $"{" ".Repeat(12)}new {nameof(ChineseWord)} " + $"{{ " + $"{nameof(ChineseWord.Simplified)} = \"{chineseWord.Simplified}\"" + $", {nameof(ChineseWord.Traditional)} = \"{chineseWord.Traditional}\"" + $", {nameof(ChineseWord.SimplifiedPinyin)} = \"{chineseWord.SimplifiedPinyin}\"" + $", {nameof(ChineseWord.TraditionalPinyin)} = \"{chineseWord.TraditionalPinyin}\"" + $", {nameof(ChineseWord.Tag)} = {chineseWord.Tag}" + $" }},"; sb.AppendLine(line); total += 1; } } } sb.AppendLine($@"{" ".Repeat(12)}new {nameof(ChineseWord)} {{ Simplified = ""两"", Traditional = ""两"", SimplifiedPinyin = ""liang3"", TraditionalPinyin = ""liang3"", Tag = 2 }},"); sb.AppendLine($@"{" ".Repeat(12)}new {nameof(ChineseWord)} {{ Simplified = ""两百"", Traditional = ""两百"", SimplifiedPinyin = ""liang3 bai3"", TraditionalPinyin = ""liang3 bai3"", Tag = 200 }},"); sb.AppendLine($@"{" ".Repeat(12)}new {nameof(ChineseWord)} {{ Simplified = ""两千"", Traditional = ""两千"", SimplifiedPinyin = ""liang3 qian1"", TraditionalPinyin = ""liang3 qian1"", Tag = 2000 }},"); total += 3; sb.AppendLine($@"{" ".Repeat(12)}// Total {total} words."); return(Wrap(sb.ToString()).Replace("she4", "shi2")); // 拾 = shi2 }
public void ChineseLexiconTest() { var str = "他是重量级选手。"; Assert.Equal("ta1 shi4 chong2 liang2 ji2 shua1 shou3。", Pinyin.GetString(str, PinyinFormat.Default)); var words = new ChineseWord[] { new ChineseWord { Pinyin = "zhong4 liang4", Simplified = "重量", Traditional = "重量" }, }; using (new ChineseLexicon(words)) { Assert.Equal("ta1 shi4 zhong4 liang4 ji2 shua1 shou3。", Pinyin.GetString(str, PinyinFormat.Default)); } }
public void ChineseLexiconTest() { var str = "他是重量级选手。"; var pinyin = Pinyin.GetString(str, PinyinFormat.Default); Assert.Equal("ta1 shi4 chong2 liang2 ji2 shua1 shou3。".Flow(StringFlow.HexString), pinyin.Flow(StringFlow.HexString)); var words = new ChineseWord[] { new ChineseWord { Pinyins = new[] { "zhong4 liang4" }, Simplified = "重量", Traditional = "重量" }, }; using (new ChineseLexicon(BuiltinWords.Basic, words)) { Assert.Equal("ta1 shi4 zhong4 liang4 ji2 shua1 shou3。", Pinyin.GetString(str, PinyinFormat.Default)); } }
public void ChineseLexiconTest1() { var str = "他是来自重庆的重量级选手。"; var pinyin = Pinyin.GetString(str, PinyinFormat.Default); Assert.Equal("ta1 shi4 lai2 zi4 zhong4 qing4 de5 zhong4 liang4 ji2 xuan3 shou3。", pinyin); var words = new ChineseWord[] { new ChineseWord { Simplified = "重庆", Traditional = "重慶", Pinyin = "chong2 qing4" }, new ChineseWord { Simplified = "重量", Traditional = "重量", Pinyin = "zhong4 liang4" }, }; using (new ChineseLexicon(Builtin.ChineseChars, words).BeginScope()) { Assert.Equal("ta1 shi4 lai2 zi4 chong2 qing4 de5 zhong4 liang4 ji2 xuan3 shou3。", Pinyin.GetString(str, PinyinFormat.Default)); } }