Пример #1
0
 internal static void ResourceToTxt(string strTxtFile)
 {
     using (FileStream fileStream = new FileStream(strTxtFile, FileMode.Create, FileAccess.Write))
     {
         using (StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
         {
             streamWriter.Write(ChinesePinyin.charDictionary.Count);
             streamWriter.WriteLine("");
             for (int index = 0; index < ChinesePinyin.charDictionary.Count; index++)
             {
                 CharUnit charUnit = ChinesePinyin.charDictionary.CharUnitTable[index];
                 streamWriter.Write(charUnit.Char);
                 streamWriter.Write(" ");
                 streamWriter.Write((int)charUnit.m_strokeNumber);
                 streamWriter.Write(" ");
                 streamWriter.Write((int)charUnit.m_pinyinCount);
                 for (int index2 = 0; index2 < (int)charUnit.m_pinyinCount; index2++)
                 {
                     PinyinUnit pinYinUnitByIndex = ChinesePinyin.pinyinDictionary.GetPinYinUnitByIndex((int)charUnit.PinyinIndexList[index2]);
                     streamWriter.Write(" ");
                     streamWriter.Write(pinYinUnitByIndex.Pinyin);
                 }
                 streamWriter.WriteLine("");
             }
         }
     }
 }
Пример #2
0
        internal static PinyinUnit Deserialize(BinaryReader binaryReader)
        {
            PinyinUnit unit = new PinyinUnit();

            byte[] bytes = binaryReader.ReadBytes(7);
            unit.Pinyin = Encoding.ASCII.GetString(bytes, 0, 7);
            char[] trimChars = new char[1];
            unit.Pinyin = unit.Pinyin.TrimEnd(trimChars);
            return(unit);
        }
Пример #3
0
        internal static PinyinDictionary Deserialize(BinaryReader binaryReader)
        {
            PinyinDictionary dictionary = new PinyinDictionary();

            binaryReader.ReadInt32();
            dictionary.Length = binaryReader.ReadInt16();
            dictionary.Count  = binaryReader.ReadInt16();
            dictionary.Offset = binaryReader.ReadInt16();
            binaryReader.ReadBytes(8);
            dictionary.PinyinUnitTable = new List <PinyinUnit>();
            for (int i = 0; i < (int)dictionary.Count; i++)
            {
                dictionary.PinyinUnitTable.Add(PinyinUnit.Deserialize(binaryReader));
            }
            binaryReader.ReadInt16();
            return(dictionary);
        }
Пример #4
0
        private void DoConvertToPinyin()
        {
            StringBuilder stringBuilder = new StringBuilder();
            List <char>   list          = new List <char>();
            List <string> list2         = new List <string>();

            this.ClearResult();
            for (int index = 0; index < this.m_chineseString.Length; index++)
            {
                char   index2 = this.m_chineseString[index];
                string str    = "";
                char   ch     = '\0';
                bool   flag   = false;
                bool   flag2  = false;
                list2.Clear();
                bool flag3 = ChinesePinyin.IsChineseLetter(index2);
                if (flag3)
                {
                    bool flag4 = index == 0;
                    if (flag4)
                    {
                        this.m_chineseCharacter = index2;
                    }
                    CharUnit charUnit = ChinesePinyin.charDictionary.GetCharUnit(index2);
                    bool     flag5    = charUnit != null;
                    if (flag5)
                    {
                        int        num = (int)charUnit.m_pinyinCount;
                        PinyinUnit pinYinUnitByIndex = ChinesePinyin.pinyinDictionary.GetPinYinUnitByIndex((int)charUnit.PinyinIndexList[0]);
                        bool       flag6             = pinYinUnitByIndex != null;
                        if (flag6)
                        {
                            str = pinYinUnitByIndex.Pinyin.Substring(0, pinYinUnitByIndex.Pinyin.Length - 1).ToLower();
                            ch  = pinYinUnitByIndex.Pinyin[0];
                            list2.Add(str);
                            bool flag7 = index == 0;
                            if (flag7)
                            {
                                this.m_strokeNumber  = (short)charUnit.m_strokeNumber;
                                this.m_pinyinCount   = (short)charUnit.m_pinyinCount;
                                this.m_isPolyphone   = (this.m_pinyinCount > 1);
                                this.m_pinyinList[0] = pinYinUnitByIndex.Pinyin.ToLower();
                            }
                        }
                        for (int index3 = 1; index3 < num; index3++)
                        {
                            PinyinUnit pinYinUnitByIndex2 = ChinesePinyin.pinyinDictionary.GetPinYinUnitByIndex((int)charUnit.PinyinIndexList[index3]);
                            bool       flag8 = pinYinUnitByIndex2 != null;
                            if (flag8)
                            {
                                string str2  = pinYinUnitByIndex2.Pinyin.ToLower();
                                bool   flag9 = index == 0;
                                if (flag9)
                                {
                                    this.m_pinyinList[index3] = str2;
                                }
                                string str3   = str2.Substring(0, str2.Length - 1);
                                bool   flag10 = !list2.Contains(str3);
                                if (flag10)
                                {
                                    list2.Add(str3);
                                    flag = true;
                                    bool flag11 = ch != pinYinUnitByIndex2.Pinyin[0];
                                    if (flag11)
                                    {
                                        flag2 = true;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    str = index2.ToString();
                    ch  = index2;
                }
                bool flag12 = ChinesePinyin.pinyinCustom.ContainsKey(index2);
                if (flag12)
                {
                    string str4 = ChinesePinyin.pinyinCustom[index2];
                    str = str4.ToLower();
                    bool flag13 = str4.Length > 0;
                    if (flag13)
                    {
                        ch = str4[0];
                    }
                }
                bool flag14 = str != "";
                if (flag14)
                {
                    stringBuilder.Append(str);
                    this.m_strShouZiMu += ch.ToString();
                    bool flag15 = flag && !list.Contains(index2);
                    if (flag15)
                    {
                        list.Add(index2);
                        string str5 = "";
                        for (int index4 = 0; index4 < list2.Count; index4++)
                        {
                            bool flag16 = str5 != "";
                            if (flag16)
                            {
                                str5 += " ";
                            }
                            str5 += list2[index4];
                        }
                        this.m_strPolyphone1 = string.Concat(new string[]
                        {
                            this.m_strPolyphone1,
                            index2.ToString(),
                            "(",
                            str5,
                            ")"
                        });
                        bool flag17 = flag2;
                        if (flag17)
                        {
                            this.m_strPolyphone2 = string.Concat(new string[]
                            {
                                this.m_strPolyphone2,
                                index2.ToString(),
                                "(",
                                str5,
                                ")"
                            });
                        }
                    }
                }
                else
                {
                    this.m_unknownChars += index2.ToString();
                    bool flag18 = this.m_unknownFill != "";
                    if (flag18)
                    {
                        stringBuilder.Append(this.m_unknownFill);
                        this.m_strShouZiMu += this.m_unknownFill;
                    }
                    else
                    {
                        stringBuilder.Append(index2);
                        this.m_strShouZiMu += index2.ToString();
                    }
                }
            }
            this.m_strPinYin = stringBuilder.ToString();
        }
Пример #5
0
 internal bool Match(PinyinUnit pinyinUnit)
 {
     return(string.Compare(pinyinUnit.Pinyin, this.ExpectedPinyin, true, CultureInfo.CurrentCulture) == 0);
 }