Exemple #1
0
        static void SimplifyPinYinWords(HashSet <PinYinWords> pyws, List <PinYinWords> list, int length)
        {
            foreach (var item in pyws)
            {
                var w = item.Words;
                if (w.Length != length)
                {
                    continue;
                }
                foreach (var pyw in pyws)
                {
                    if (pyw.Words.Length >= length)
                    {
                        continue;
                    }
                    w = w.Replace(pyw.Words, pyw.PinYins);
                }
                var py  = WordsHelper.GetPinYinFast(w).ToLower().Replace("'", "");
                var py1 = item.PinYins.Replace("'", "");

                if (py != py1)
                {
                    list.Add(item);
                }
            }
        }
Exemple #2
0
        static void SimplifyPinYin(List <Tuple <string, string> > list, HashSet <PinYinWords> pyws, int length)
        {
            foreach (var item in list)
            {
                if (item.Item1.Length != length)
                {
                    continue;
                }
                var w = item.Item1;
                foreach (var pyw in pyws)
                {
                    if (pyw.Words.Length >= length)
                    {
                        continue;
                    }

                    w = w.Replace(pyw.Words, pyw.PinYins);
                }
                var py  = WordsHelper.GetPinYinFast(w).ToLower().Replace("'", "");
                var py1 = item.Item2.Replace("'", "");

                if (py != py1)
                {
                    PinYinWords p = new PinYinWords()
                    {
                        Words   = item.Item1,
                        PinYins = item.Item2
                    };
                    pyws.Add(p);
                }
            }
        }
        public void GetPinYin()
        {
            var t = WordsHelper.GetAllPinYin('芃');

            Assert.AreEqual("Peng", t[0]);

            var a = WordsHelper.GetPinYinFast("阿");

            Assert.AreEqual("A", a);


            var b = WordsHelper.GetPinYin("摩擦棒");

            Assert.AreEqual("MoCaBang", b);

            b = WordsHelper.GetPinYin("秘鲁");
            Assert.AreEqual("BiLu", b);



            var py = WordsHelper.GetPinYinFast("我爱中国");

            Assert.AreEqual("WoAiZhongGuo", py);



            py = WordsHelper.GetPinYin("快乐,乐清");
            Assert.AreEqual("KuaiLe,YueQing", py);

            py = WordsHelper.GetPinYin("快乐清理");
            Assert.AreEqual("KuaiLeQingLi", py);


            py = WordsHelper.GetPinYin("我爱中国");
            Assert.AreEqual("WoAiZhongGuo", py);

            py = WordsHelper.GetPinYin("我爱中国", true);
            Assert.AreEqual("WǒÀiZhōngGuó", py);

            py = WordsHelper.GetFirstPinYin("我爱中国");
            Assert.AreEqual("WAZG", py);

            var pys = WordsHelper.GetAllPinYin('传');

            Assert.AreEqual("Chuan", pys[0]);
            Assert.AreEqual("Zhuan", pys[1]);

            py = WordsHelper.GetPinYinForName("单一一");
            Assert.AreEqual("ShanYiYi", py);

            py = WordsHelper.GetPinYinForName("单一一", true);
            Assert.AreEqual("ShànYīYī", py);
        }
Exemple #4
0
        static void GetPinYinWords(string file, HashSet <PinYinWords> pyws)
        {
            SougouPinyinScel scel = new SougouPinyinScel();
            var t = scel.Import(file);
            List <Tuple <string, string> > list = new List <Tuple <string, string> >();

            foreach (var item in t)
            {
                var w   = item.Word;
                var py  = WordsHelper.GetPinYinFast(w).ToLower();
                var py1 = item.PinYinString.Replace("'", "");
                if (py != py1)
                {
                    list.Add(Tuple.Create(w, item.PinYinString));
                }
            }
            for (int i = 2; i < 5; i++)
            {
                SimplifyPinYin(list, pyws, i);
            }
        }
Exemple #5
0
        public void GetPinYin()
        {
            var t = WordsHelper.GetAllPinYin('芃');

            Assert.AreEqual("Peng", t[0]);

            var a = WordsHelper.GetPinYinFast("阿");

            Assert.AreEqual("A", a);


            var b = WordsHelper.GetPinYin("摩擦棒");

            Assert.AreEqual("MoCaBang", b);

            b = WordsHelper.GetPinYin("秘鲁");
            Assert.AreEqual("BiLu", b);



            var py = WordsHelper.GetPinYinFast("我爱中国");

            Assert.AreEqual("WoAiZhongGuo", py);



            py = WordsHelper.GetPinYin("快乐,乐清");
            Assert.AreEqual("KuaiLe,YueQing", py);

            py = WordsHelper.GetPinYin("我爱中国");
            Assert.AreEqual("WoAiZhongGuo", py);

            py = WordsHelper.GetFirstPinYin("我爱中国");
            Assert.AreEqual("WAZG", py);

            var pys = WordsHelper.GetAllPinYin('传');

            Assert.AreEqual("Chuan", pys[0]);
            Assert.AreEqual("Zhuan", pys[1]);
        }