拼音检索

简介: 当我们遇到要处理汉字和拼音之间的转化关系怎么办?如和用程序来实现? 我搜索到一个ChineseChar开发包,然后实现了这一难题 using System; using Microsoft.

当我们遇到要处理汉字和拼音之间的转化关系怎么办?如和用程序来实现?

我搜索到一个ChineseChar开发包,然后实现了这一难题

using System;
using Microsoft.International.Converters.PinYinConverter;

namespace 拼音基础
{
    class Program
    {
        static void Main(string[] args)
        {

            #region 判断是否为同音字
            ChineseChar chineseChar = new ChineseChar('微');
            Console.WriteLine("Stroke number of 微 in Chinese is {0}.", chineseChar.StrokeNumber);
            Console.WriteLine("{0} characters' pinyin is \"wei1\".", ChineseChar.GetHomophoneCount("wei1"));
            if (ChineseChar.IsHomophone('微', '薇'))
            {
                Console.WriteLine("微 and 薇 have the same pinyin.");
            }
            else
            {
                Console.WriteLine("微 and 薇 have different pinyins.");
            }
            #endregion
            ChineseChar char1 = new ChineseChar('单');
            bool f = ChineseChar.IsHomophone('杨','洋');
            Console.Write("杨和洋是否为同音字"+f);
            Console.Write("\n单是否为多音字:"+char1.IsPolyphone);
            char[] chars = ChineseChar.GetChars("ji3");//要加上声调
            foreach (char c in chars)
            {
                Console.Write(c + " ");
            }

            for (int i = 0; i < char1.PinyinCount; i++)
            {
                string s=char1.Pinyins[i];
                Console.WriteLine(s);
            }
           
           
            //判断是否是一个拼音字符串
            Console.WriteLine("de是否是一个合法的拼音"+ChineseChar.IsValidPinyin("de1"));//1,2,3,4表示声调

            #region 输入一段中文,写出拼音
            string str = Console.ReadLine();
            foreach (char c in str)
            {
                if (ChineseChar.IsValidChar(c))
                {
                    ChineseChar cc = new ChineseChar(c);
                    Console.Write(cc.Pinyins[0] + " ");
                }
                else
                {
                    Console.Write(c);
                }
            }
            #endregion

            Console.Read();
        }
    }
}

 

相关文章
|
9月前
leetcode-212:单词搜索 II
leetcode-212:单词搜索 II
57 0
|
9月前
leetcode-79:单词搜索
leetcode-79:单词搜索
61 0
|
自然语言处理 算法
中文文本处理分词的二元模型
中文文本处理分词的二元模型
205 1
中文文本处理分词的二元模型
|
canal 搜索推荐 关系型数据库
拼音分词器
安装方式参考IK分词器
295 0
|
自然语言处理
|
机器学习/深度学习 自然语言处理 Python
中文自然语言处理工具集:分词,相似度匹配
欢迎大家关注我们的网站和系列教程:http://www.tensorflownews.com/,学习更多的机器学习、深度学习的知识! 分词工具 结巴分词 https://github.
2445 0
|
人工智能 关系型数据库 MySQL