コード例 #1
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());
        }