Пример #1
0
 public string Translate(string content)
 {
     if (_settings.ShouldUsePinyin)
     {
         if (!_pinyinCache.ContainsKey(content))
         {
             if (WordsHelper.HasChinese(content))
             {
                 var result = WordsHelper.GetPinyin(content, ";");
                 result = GetFirstPinyinChar(result) + result.Replace(";", "");
                 _pinyinCache[content] = result;
                 return(result);
             }
             else
             {
                 return(content);
             }
         }
         else
         {
             return(_pinyinCache[content]);
         }
     }
     else
     {
         return(content);
     }
 }
Пример #2
0
        public void GetPinyin()
        {
            var t = WordsHelper.GetAllPinyin('芃');

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


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

            Assert.AreEqual("MoCaBang", b);

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

            b = WordsHelper.GetPinyin("天行");
            Assert.AreEqual("TianXing", b);

            var 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("我爱中国", ",");
            Assert.AreEqual("Wo,Ai,Zhong,Guo", 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("单一一", ",");
            Assert.AreEqual("Shan,Yi,Yi", py);

            py = WordsHelper.GetPinyinForName("单一一", true);
            Assert.AreEqual("ShànYīYī", py);

            py = WordsHelper.GetPinyinForName("张丽莎", false);
            Assert.AreEqual("ZhangLiSha", py);

            py = WordsHelper.GetPinyinForName("孟露", false);
            Assert.AreEqual("MengLu", py);


            WordsHelper.ClearCache();
        }
Пример #3
0
 /// <summary>
 /// 获取拼音
 /// </summary>
 /// <param name="source"></param>
 /// <param name="separator"></param>
 /// <param name="tone"></param>
 /// <param name="forName"></param>
 /// <returns></returns>
 private static string GetPinyinInternal(string source, string separator, bool tone, bool forName)
 {
     if (forName)
     {
         return(WordsHelper.GetPinyinForName(source, separator, tone));
     }
     else
     {
         return(WordsHelper.GetPinyin(source, separator, tone));
     }
 }
Пример #4
0
        static void Main(string[] args)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();
            var r         = WordsHelper.GetPinyin("我爱中国");

            stopwatch.Stop();
            var s = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("拼音第一次加载用时(ms):" + s);

            PetaTest.Runner.RunMain(args);
        }
 public void SetKeys(List <string> keys)
 {
     if (keys != null && keys.Any())
     {
         var allKeys = new List <string>();
         foreach (var k in keys)
         {
             allKeys.Add(k);                                   // 增加词汇
             allKeys.Add(WordsHelper.ToTraditionalChinese(k)); // 增加繁体
             allKeys.Add(WordsHelper.GetPinyin(k));            // 增加拼音
         }
         IllegalWordsSearch.SetKeywords(allKeys);
     }
 }
Пример #6
0
 /// <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);
 }
Пример #7
0
        public void GetPinyin()
        {
            var list = WordsHelper.GetAllPinyin('㘄');

            list = WordsHelper.GetAllPinyin('䉄');
            list = WordsHelper.GetAllPinyin('䬋');
            list = WordsHelper.GetAllPinyin('䮚');
            list = WordsHelper.GetAllPinyin('䚏');
            list = WordsHelper.GetAllPinyin('㭁');
            list = WordsHelper.GetAllPinyin('䖆');

            var list2 = WordsHelper.GetPinyin("𠀀");
            var list3 = WordsHelper.GetPinyin("𫠝");
            //var start = "𠀀";// '\ud840' '\udc00' - '\udfff'
            //var end = "𫠝";// '\ud86e' '\udc1d'
        }
Пример #8
0
        public void GetPinyin()
        {
            var list = WordsHelper.GetAllPinyin('㘄');

            list = WordsHelper.GetAllPinyin('䉄');
            list = WordsHelper.GetAllPinyin('䬋');
            list = WordsHelper.GetAllPinyin('䮚');
            list = WordsHelper.GetAllPinyin('䚏');
            list = WordsHelper.GetAllPinyin('㭁');
            list = WordsHelper.GetAllPinyin('䖆');

            var list2 = WordsHelper.GetPinyin("𠀀");
            var list3 = WordsHelper.GetPinyin("𫠝");
            //var start = "𠀀";// '\ud840' '\udc00' - '\udfff'
            //var end = "𫠝";// '\ud86e' '\udc1d'

            var t   = "三个金念鑫,三个水念淼,三个火念焱, 三个土念垚,三个牛念犇,三个手念掱,三个目念瞐,三个田念畾,三个马念骉,三个羊念羴,三个犬念猋,三个鹿念麤,三个鱼念鱻,三个贝念赑,三个力念劦,三个毛念毳,三个耳念聶,三个车念轟,三个直念矗,三个龙念龘,三个原念厵,三个雷念靐,三个飞念飝,三个刀念刕,三个又念叒,三个士念壵,三个小念尛,三个子念孨,三个止念歮,三个风念飍,三个隼念雥,三个吉念嚞,三个言念譶,三个舌念舙,三个香念馫,三个泉念灥,三个心念惢,三个白念皛";
            var pys = ToolGood.Words.WordsHelper.GetPinyin(t);
        }
Пример #9
0
 public ValidationResult IsValid(object value, ValidationContext validationContext)
 {
     if (value is string v)
     {
         if (!String.IsNullOrEmpty(v))
         {
             if (MinGanProvider.Instance.IllegalWordsSearch.ContainsAny(v))
             {
                 return(new ValidationResult("存在敏感词", new[] { validationContext.MemberName }));
             }
             // 检查拼音
             if (MinGanProvider.Instance.IllegalWordsSearch.ContainsAny(WordsHelper.GetPinyin(v)))
             {
                 return(new ValidationResult("存在敏感词", new [] { validationContext.MemberName }));
             }
             // todo:其他变种
         }
     }
     return(ValidationResult.Success);
 }
Пример #10
0
        static void Main(string[] args)
        {
            // 转成简体
            var str = WordsHelper.ToSimplifiedChinese("壹佰贰拾叁億肆仟伍佰陆拾柒萬捌仟玖佰零壹元壹角贰分");

            Console.WriteLine(str);

            // 转成繁体
            var str2 = WordsHelper.ToTraditionalChinese("壹佰贰拾叁亿肆仟伍佰陆拾柒万捌仟玖佰零壹元壹角贰分");

            Console.WriteLine(str2);

            // 转成全角
            var str3 = WordsHelper.ToSBC("abcABC123");

            Console.WriteLine(str3);

            // 转成半角
            var str4 = WordsHelper.ToDBC("abcABC123");

            Console.WriteLine(str4);

            // 数字转成中文大写
            var str5 = WordsHelper.ToChineseRMB(12345678901.12);

            Console.WriteLine(str5);

            // 中文转成数字
            var str6 = WordsHelper.ToNumber("壹佰贰拾叁亿肆仟伍佰陆拾柒万捌仟玖佰零壹元壹角贰分");

            Console.WriteLine(str6);

            // 获取全拼
            var str7 = WordsHelper.GetPinyin("我爱中国");

            Console.WriteLine(str7);

            // 获取首字母
            var str8 = WordsHelper.GetFirstPinyin("我爱中国");

            Console.WriteLine(str8);

            // 获取全部拼音
            var str9 = WordsHelper.GetAllPinyin('传');

            Console.WriteLine(str9);

            // 获取姓名
            var str10 = WordsHelper.GetPinyinForName("单一一");

            Console.WriteLine(str10);
            var str11 = WordsHelper.GetPinyinForName("单一一", ",");

            Console.WriteLine(str11);
            var str12 = WordsHelper.GetPinyinForName("单一一", true);

            Console.WriteLine(str12);

            string      s     = "北京|天津|河北|辽宁|吉林|黑龙江|山东|江苏|上海|浙江|安徽|福建|江西|广东|广西|海南|河南|湖南|湖北|山西|内蒙古|宁夏|青海|陕西|甘肃|新疆|四川|贵州|云南|重庆|西藏|香港|澳门|台湾";
            PinyinMatch match = new PinyinMatch();

            match.SetKeywords(s.Split('|').ToList());
            var all = match.Find("BJ");

            Console.WriteLine(all[0]);
            Console.WriteLine(all.Count);

            all = match.Find("北J");
            Console.WriteLine(all[0]);
            Console.WriteLine(all.Count);
        }