/// <summary> /// 识别给出的两个字符是否是同音字。 /// </summary> /// <param name="ch1">指出第一个字符</param> /// <param name="ch2">指出第二个字符</param> /// <returns>如果给出的字符是同音字返回ture,否则返回false。</returns> public static bool IsHomophone(char ch1, char ch2) { CharUnit charUnit = ChineseChar.charDictionary.GetCharUnit(ch1); CharUnit charUnit2 = ChineseChar.charDictionary.GetCharUnit(ch2); return(ChineseChar.ExistSameElement <short>(charUnit.PinyinIndexList, charUnit2.PinyinIndexList)); }
/// <summary> /// 检索具有指定笔画数的字符个数。 /// </summary> /// <param name="strokeNumber">显示需要被识别的笔画数。</param> /// <returns>返回具有指定笔画数的字符数。 如果笔画数是无效值返回-1。</returns> public static short GetCharCount(short strokeNumber) { if (!ChineseChar.IsValidStrokeNumber(strokeNumber)) { return(-1); } return(ChineseChar.strokeDictionary.GetStrokeUnit((int)strokeNumber).CharCount); }
/// <summary> /// 检索具有指定笔画数的所有字符串。 /// </summary> /// <param name="strokeNumber">指出需要被识别的笔画数。</param> /// <returns>返回具有指定笔画数的字符列表。 如果笔画数是无效值返回空。</returns> public static char[] GetChars(short strokeNumber) { if (!ChineseChar.IsValidStrokeNumber(strokeNumber)) { return(null); } StrokeUnit strokeUnit = ChineseChar.strokeDictionary.GetStrokeUnit((int)strokeNumber); return(strokeUnit.CharList); }
/// <summary> /// 检索指定字符的笔画数。 /// </summary> /// <param name="ch">指出需要识别的字符。</param> /// <returns>返回指定字符的笔画数。 如果字符不是有效值则返回-1。 </returns> public static short GetStrokeNumber(char ch) { if (!ChineseChar.IsValidChar(ch)) { return(-1); } CharUnit charUnit = ChineseChar.charDictionary.GetCharUnit(ch); return((short)charUnit.StrokeNumber); }
/// <summary> /// 检索具有指定拼音的字符数。 /// </summary> /// <param name="pinyin">显示需要被识别的拼音字符串。</param> /// <returns>返回具有指定拼音的字符数。 如果拼音不是有效值则返回-1。</returns> public static short GetHomophoneCount(string pinyin) { if (pinyin == null) { throw new ArgumentNullException("pinyin"); } if (!ChineseChar.IsValidPinyin(pinyin)) { return(-1); } return(ChineseChar.homophoneDictionary.GetHomophoneUnit(ChineseChar.pinyinDictionary, pinyin).Count); }
/// <summary> /// 获取给定拼音的所有同音字。 /// </summary> /// <param name="pinyin">指出读音。</param> /// <returns>返回具有相同的指定拼音的字符串列表。 如果拼音不是有效值则返回空。 </returns> public static char[] GetChars(string pinyin) { if (pinyin == null) { throw new ArgumentNullException("pinyin"); } if (!ChineseChar.IsValidPinyin(pinyin)) { return(null); } HomophoneUnit homophoneUnit = ChineseChar.homophoneDictionary.GetHomophoneUnit(ChineseChar.pinyinDictionary, pinyin); return(homophoneUnit.HomophoneList); }
/// <summary> /// ChineseChar类的构造函数。 /// </summary> /// <param name="ch">指定的汉字字符。</param> public ChineseChar(char ch) { if (!ChineseChar.IsValidChar(ch)) { throw new NotSupportedException(AssemblyResource.CHARACTER_NOT_SUPPORTED); } this.chineseCharacter = ch; CharUnit charUnit = ChineseChar.charDictionary.GetCharUnit(ch); this.strokeNumber = (short)charUnit.StrokeNumber; this.pinyinCount = (short)charUnit.PinyinCount; this.isPolyphone = (charUnit.PinyinCount > 1); for (int i = 0; i < (int)this.pinyinCount; i++) { PinyinUnit pinYinUnitByIndex = ChineseChar.pinyinDictionary.GetPinYinUnitByIndex((int)charUnit.PinyinIndexList[i]); this.pinyinList[i] = pinYinUnitByIndex.Pinyin; } }
/// <summary> /// 汉字转化为拼音首字母 /// </summary> /// <param name="str">汉字</param> /// <returns>首字母</returns> public string GetFirstPinyin(string str) { string r = string.Empty; foreach (char obj in str) { try { Microsoft.International.Converters.PinYinConverter.ChineseChar chineseChar = new Microsoft.International.Converters.PinYinConverter.ChineseChar(obj); string t = chineseChar.Pinyins[0].ToString(); r += t.Substring(0, 1); } catch { r += obj.ToString(); } } return(r); }
//API public string GetFirstPinyin(string strHanZiArray) { string strFirstPinYinArray = string.Empty; foreach (char obj in strHanZiArray) { try { Microsoft.International.Converters.PinYinConverter.ChineseChar chineseChar = new Microsoft.International.Converters.PinYinConverter.ChineseChar(obj); string strTemp = chineseChar.Pinyins[0].ToString(); //PU //P strFirstPinYinArray += strTemp.Substring(0, 1); } catch { strFirstPinYinArray += obj.ToString(); } } return(strFirstPinYinArray); }
//API public string GetHanZiArray_PinYin_Full_0(string strHanZiArray) { string strPinYinFull_0 = string.Empty; foreach (char obj in strHanZiArray) { try { Microsoft.International.Converters.PinYinConverter.ChineseChar chineseChar = new Microsoft.International.Converters.PinYinConverter.ChineseChar(obj); //PU3 //PU5 string strTemp = chineseChar.Pinyins[0].ToString(); //PU strPinYinFull_0 += strTemp.Substring(0, strTemp.Length - 1); strPinYinFull_0 += " "; } catch { strPinYinFull_0 += obj.ToString(); } } return(strPinYinFull_0); }
//API public string GetHanZi_PinYin_Full_4(string strOneHanZi) { string strPinYinFull_4 = string.Empty; foreach (char obj in strOneHanZi) { try { Microsoft.International.Converters.PinYinConverter.ChineseChar chineseChar = new Microsoft.International.Converters.PinYinConverter.ChineseChar(obj); //PU3 //PU5 string strTemp = chineseChar.Pinyins[0].ToString(); //PU3 strPinYinFull_4 += strTemp; } catch { strPinYinFull_4 += obj.ToString(); } break; } return(strPinYinFull_4); }
/// <summary> /// 识别给出的字符是否是实例字符的同音字。 /// </summary> /// <param name="ch">指出需要识别的字符。</param> /// <returns>如果给出的实例字符是同音字则返回ture,否则返回false。</returns> public bool IsHomophone(char ch) { return(ChineseChar.IsHomophone(this.chineseCharacter, ch)); }