Exemplo n.º 1
0
 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(@"歌词不能为空。");
     }
 }
Exemplo n.º 2
0
        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());
        }