Exemplo n.º 1
0
        static ChineseChar()
        {
            var executingAssembly = Assembly.GetExecutingAssembly();

            using (var manifestResourceStream = executingAssembly.GetManifestResourceStream("Dragon.Framework.Infrastructure.Pinyin.Resources.PinyinDictionary.resources"))
            {
                using (var resourceReader = new ResourceReader(manifestResourceStream ?? Stream.Null))
                {
                    resourceReader.GetResourceData("PinyinDictionary", out _, out var buffer);
                    using (var binaryReader = new BinaryReader(new MemoryStream(buffer)))
                    {
                        PinyinDictionary = PinyinDictionary.Deserialize(binaryReader);
                    }
                }
            }
            using (var manifestResourceStream2 = executingAssembly.GetManifestResourceStream("Dragon.Framework.Infrastructure.Pinyin.Resources.CharDictionary.resources"))
            {
                using (var resourceReader2 = new ResourceReader(manifestResourceStream2 ?? Stream.Null))
                {
                    resourceReader2.GetResourceData("CharDictionary", out _, out var buffer);
                    using (var binaryReader2 = new BinaryReader(new MemoryStream(buffer)))
                    {
                        CharDictionary = CharDictionary.Deserialize(binaryReader2);
                    }
                }
            }
            using (var manifestResourceStream3 = executingAssembly.GetManifestResourceStream("Dragon.Framework.Infrastructure.Pinyin.Resources.HomophoneDictionary.resources"))
            {
                using (var resourceReader3 = new ResourceReader(manifestResourceStream3 ?? Stream.Null))
                {
                    resourceReader3.GetResourceData("HomophoneDictionary", out _, out var buffer);
                    using (var binaryReader3 = new BinaryReader(new MemoryStream(buffer)))
                    {
                        HomophoneDictionary = HomophoneDictionary.Deserialize(binaryReader3);
                    }
                }
            }
            using (var manifestResourceStream4 = executingAssembly.GetManifestResourceStream("Dragon.Framework.Infrastructure.Pinyin.Resources.StrokeDictionary.resources"))
            {
                using (var resourceReader4 = new ResourceReader(manifestResourceStream4 ?? Stream.Null))
                {
                    resourceReader4.GetResourceData("StrokeDictionary", out _, out var buffer);
                    using (var binaryReader4 = new BinaryReader(new MemoryStream(buffer)))
                    {
                        StrokeDictionary = StrokeDictionary.Deserialize(binaryReader4);
                    }
                }
            }
        }
Exemplo n.º 2
0
        internal static PinyinDictionary Deserialize(BinaryReader binaryReader)
        {
            var pinyinDictionary = new PinyinDictionary();

            binaryReader.ReadInt32();
            pinyinDictionary.Length = binaryReader.ReadInt16();
            pinyinDictionary.Count  = binaryReader.ReadInt16();
            pinyinDictionary.Offset = binaryReader.ReadInt16();
            binaryReader.ReadBytes(8);
            pinyinDictionary.PinyinUnitTable = new List <PinyinUnit>();
            for (var i = 0; i < pinyinDictionary.Count; i++)
            {
                pinyinDictionary.PinyinUnitTable.Add(PinyinUnit.Deserialize(binaryReader));
            }
            binaryReader.ReadInt16();
            return(pinyinDictionary);
        }
Exemplo n.º 3
0
 internal HomophoneUnit GetHomophoneUnit(PinyinDictionary pinyinDictionary, string pinyin)
 {
     return(GetHomophoneUnit(pinyinDictionary.GetPinYinUnitIndex(pinyin)));
 }