示例#1
0
        public static bool IsHomophone(char ch1, char ch2)
        {
            CharUnit charUnit = charDictionary.GetCharUnit(ch1);
            CharUnit unit2    = charDictionary.GetCharUnit(ch2);

            return(ExistSameElement <short>(charUnit.PinyinIndexList, unit2.PinyinIndexList));
        }
示例#2
0
        /// <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);
        }
示例#3
0
        internal static CharUnit Deserialize(BinaryReader binaryReader)
        {
            CharUnit charUnit = new CharUnit();

            charUnit.Char            = binaryReader.ReadChar();
            charUnit.StrokeNumber    = binaryReader.ReadByte();
            charUnit.PinyinCount     = binaryReader.ReadByte();
            charUnit.PinyinIndexList = new short[(int)charUnit.PinyinCount];
            for (int index = 0; index < (int)charUnit.PinyinCount; ++index)
            {
                charUnit.PinyinIndexList[index] = binaryReader.ReadInt16();
            }
            return(charUnit);
        }
示例#4
0
        internal static CharDictionary Deserialize(BinaryReader binaryReader)
        {
            CharDictionary charDictionary = new CharDictionary();

            binaryReader.ReadInt32();
            charDictionary.Length = binaryReader.ReadInt32();
            charDictionary.Count  = binaryReader.ReadInt32();
            charDictionary.Offset = binaryReader.ReadInt16();
            binaryReader.ReadBytes(24);
            charDictionary.CharUnitTable = new List <CharUnit>();
            for (int i = 0; i < charDictionary.Count; i++)
            {
                charDictionary.CharUnitTable.Add(CharUnit.Deserialize(binaryReader));
            }
            binaryReader.ReadInt16();
            return(charDictionary);
        }
示例#5
0
        public ChineseChar(char ch)
        {
            if (!IsValidChar(ch))
            {
                throw new NotSupportedException(AssemblyResource.CHARACTER_NOT_SUPPORTED);
            }
            this.chineseCharacter = ch;
            CharUnit charUnit = charDictionary.GetCharUnit(ch);

            this.strokeNumber = charUnit.StrokeNumber;
            this.pinyinCount  = charUnit.PinyinCount;
            this.isPolyphone  = charUnit.PinyinCount > 1;
            for (int i = 0; i < this.pinyinCount; i++)
            {
                PinyinUnit pinYinUnitByIndex = pinyinDictionary.GetPinYinUnitByIndex(charUnit.PinyinIndexList[i]);
                this.pinyinList[i] = pinYinUnitByIndex.Pinyin;
            }
        }
示例#6
0
        internal static CharUnit Deserialize(BinaryReader binaryReader)
        {
            CharUnit unit;

            unit = new CharUnit {
                Char            = binaryReader.ReadChar(),
                StrokeNumber    = binaryReader.ReadByte(),
                PinyinCount     = binaryReader.ReadByte(),
                PinyinIndexList = null
            };
            unit.PinyinIndexList = new short[unit.PinyinCount];

            for (int i = 0; i < unit.PinyinCount; i++)
            {
                unit.PinyinIndexList[i] = binaryReader.ReadInt16();
            }
            return(unit);
        }
示例#7
0
        public int CompareStrokeNumber(char ch)
        {
            CharUnit charUnit = charDictionary.GetCharUnit(ch);

            return(this.StrokeNumber - charUnit.StrokeNumber);
        }
示例#8
0
 internal bool Match(CharUnit charUnit)
 {
     return(charUnit.Char == this.ExpectedChar);
 }
示例#9
0
        /// <summary>
        /// 识别给出的字符串是否是一个有效的汉字字符。
        /// </summary>
        /// <param name="ch">指出需要识别的字符。</param>
        /// <returns>如果指定的字符是一个有效的汉字字符则返回ture,否则返回false。</returns>
        public static bool IsValidChar(char ch)
        {
            CharUnit charUnit = ChineseChar.charDictionary.GetCharUnit(ch);

            return(charUnit != null);
        }
示例#10
0
        /// <summary>
        /// 将给出的字符和实例字符的笔画数进行比较。
        /// </summary>
        /// <param name="ch">显示给出的字符</param>
        /// <returns>说明比较操作的结果。 如果给出字符和实例字符的笔画数相同,返回值为 0。 如果实例字符比给出字符的笔画多,返回值为> 0。 如果实例字符比给出字符的笔画少,返回值为 &lt; 0。 </returns>
        public int CompareStrokeNumber(char ch)
        {
            CharUnit charUnit = ChineseChar.charDictionary.GetCharUnit(ch);

            return((int)(this.StrokeNumber - (short)charUnit.StrokeNumber));
        }