private void ButtonOK_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(textBoxLyrics.Text)) { listBoxWord.Items.Clear(); textBoxLyrics.Text = ChineseConverter.Convert(textBoxLyrics.Text, ChineseConversionDirection.TraditionalToSimplified); textBoxLyrics.Text = RemoveFormat(textBoxLyrics.Text); string[] sentence = textBoxLyrics.Text.Split('|'); foreach (var itemSen in sentence) { if (checkBoxDisV.Checked) { listBoxWord.Items.AddRange(ToPinyinDisV(itemSen)); } else { foreach (char itemWord in itemSen.Replace("\n", "").Replace("\r", "").Replace(" ", "")) { if (nPinyinRBox.Checked) { listBoxWord.Items.Add(ToPinyin.ByNPingyin(itemWord)); } else { listBoxWord.Items.Add(ToPinyin.ByMsIntPinyin(itemWord)); } } } } } else { MessageBox.Show(@"歌词不能为空。"); } }
/// <summary> /// 结果管道 /// </summary> /// <param name="result"></param> /// <returns></returns> public string ResultPipe(string result) { if (result.IsNullOrWhiteSpace()) { return(result); } if (Reverse == "all") { result = ReverseStr(result); } else if (Reverse == "row") { result = ReverseStr(result, true); } if (WordsHelper.HasChinese(result)) { if (ToTraditionalChinese) { result = WordsHelper.ToTraditionalChinese(result); } else if (ToSimplifiedChinese) { result = WordsHelper.ToSimplifiedChinese(result); } else if (ToPinyin != null) { result = WordsHelper.GetPinyin(result, ToPinyin.Equals("tone", StringComparison.OrdinalIgnoreCase)); } else if (ToFirstPinyin) { result = WordsHelper.GetFirstPinyin(result)?.ToLower(); } } if (Lower) { result = result?.ToLower(); } else if (Upper) { result = result?.ToUpper(); } if (SpeakWithWhiteSpace) { result = ToSpeakWithWhiteSpace(result); } return(result); }
private string[] ToPinyinDisV(string str) { Entity.PinyinDictionary dict = new Entity.PinyinDictionary(); List <string> wordList = dict.Dictionary.Keys.ToList(); List <string> wordsLeft = Segmentation.SegMmDouble(str, ref wordList); if (wordsLeft == null) { MessageBox.Show(@"意外的错误,分词失败。"); return(null); } var pinyinList = new List <string>(); foreach (string word in wordsLeft) { if (word.Length == 1 && !dict.Dictionary.ContainsKey(word)) { string pinyin; if (nPinyinRBox.Checked) { pinyin = ToPinyin.ByNPingyin(word.ToCharArray()[0]); } else { pinyin = ToPinyin.ByMsIntPinyin(word.ToCharArray()[0]); } pinyinList.Add(pinyin); } else { pinyinList.AddRange(Regex.Replace(dict.Dictionary[word].ToLower(), @"\d", "").Split(' ')); } } return(pinyinList.ToArray()); }