示例#1
0
        public void Open(byte[] contents)
        {
            int  offset = 0;
            uint magic  = BitConverter.ToUInt32(contents, offset);

            offset      += 4;
            this.Version = BitConverter.ToUInt32(contents, offset);
            if (this.Version != DicVersion)
            {
                throw new MeCabInvalidFileException("incompatible version", "");
            }

            offset += 4;

            this.Type    = (DictionaryType)BitConverter.ToUInt32(contents, offset); offset += 4;
            this.LexSize = BitConverter.ToUInt32(contents, offset); offset += 4;
            this.LSize   = BitConverter.ToUInt32(contents, offset); offset += 4;
            this.RSize   = BitConverter.ToUInt32(contents, offset); offset += 4;
            uint dSize = BitConverter.ToUInt32(contents, offset); offset += 4;
            uint tSize = BitConverter.ToUInt32(contents, offset); offset += 4;
            uint fSize = BitConverter.ToUInt32(contents, offset); offset += 4;

            offset += 4;  //dummy

            byte[] b32 = new byte[33];
            Buffer.BlockCopy(contents, offset, b32, 0, 32);
            b32[32] = 0x00;
            offset += 32;
            string charSet = StrUtils.GetString(b32, Encoding.ASCII);

            this.encoding = StrUtils.GetEncoding(charSet);

            this.da.Open(contents, ref offset, dSize);

            this.tokens = new Token[tSize / 16];
            for (int i = 0; i < this.tokens.Length; i++)
            {
                this.tokens[i] = Token.Create(contents, offset);
                offset        += 16;
            }
            this.features = new byte[(int)fSize];
            Buffer.BlockCopy(contents, offset, this.features, 0, (int)fSize);
            offset += (int)fSize;

            if (offset != contents.Length)
            {
                throw new MeCabInvalidFileException("dictionary file is broken", "");
            }
            //if (reader.BaseStream.ReadByte() != -1)
            //    throw new MeCabInvalidFileException("dictionary file is broken", this.FileName);
        }
        public unsafe void Open(BinaryReader reader)
        {
            uint magic = reader.ReadUInt32();

            //CanSeekの時のみストリーム長のチェック
            if (reader.BaseStream.CanSeek && reader.BaseStream.Length != (magic ^ DictionaryMagicID))
            {
                throw new MeCabInvalidFileException("dictionary file is broken", this.FileName);
            }

            this.Version = reader.ReadUInt32();
            if (this.Version != DicVersion)
            {
                throw new MeCabInvalidFileException("incompatible version", this.FileName);
            }

            this.Type    = (DictionaryType)reader.ReadUInt32();
            this.LexSize = reader.ReadUInt32();
            this.LSize   = reader.ReadUInt32();
            this.RSize   = reader.ReadUInt32();
            uint dSize = reader.ReadUInt32();
            uint tSize = reader.ReadUInt32();
            uint fSize = reader.ReadUInt32();

            reader.ReadUInt32(); //dummy

            string charSet = StrUtils.GetString(reader.ReadBytes(32), Encoding.ASCII);

            this.encoding = StrUtils.GetEncoding(charSet);

            this.da.Open(reader, dSize);

            this.tokens = new Token[tSize / sizeof(Token)];
            for (int i = 0; i < this.tokens.Length; i++)
            {
                this.tokens[i] = Token.Create(reader);
            }

            this.features = reader.ReadBytes((int)fSize);

            if (reader.BaseStream.ReadByte() != -1)
            {
                throw new MeCabInvalidFileException("dictionary file is broken", this.FileName);
            }
        }
示例#3
0
        public unsafe void Open(BinaryReader reader)
        {
            uint num = reader.ReadUInt32();

            if (reader.BaseStream.CanSeek && reader.BaseStream.Length != (uint)((int)num ^ -277770377))
            {
                throw new MeCabInvalidFileException("dictionary file is broken", this.FileName);
            }
            this.Version = reader.ReadUInt32();
            if (this.Version != 102)
            {
                throw new MeCabInvalidFileException("incompatible version", this.FileName);
            }
            this.Type    = (DictionaryType)reader.ReadUInt32();
            this.LexSize = reader.ReadUInt32();
            this.LSize   = reader.ReadUInt32();
            this.RSize   = reader.ReadUInt32();
            uint size  = reader.ReadUInt32();
            uint num2  = reader.ReadUInt32();
            uint count = reader.ReadUInt32();

            reader.ReadUInt32();
            string @string = StrUtils.GetString(reader.ReadBytes(32), Encoding.ASCII);

            this.encoding = Encoding.GetEncoding(@string == "UTF8" ? "UTF-8" : @string);
            this.da.Open(reader, size);
            this.tokens = new Token[(long)num2 / (long)sizeof(Token)];
            for (int i = 0; i < this.tokens.Length; i++)
            {
                this.tokens[i] = Token.Create(reader);
            }
            this.features = reader.ReadBytes((int)count);
            if (reader.BaseStream.ReadByte() == -1)
            {
                return;
            }
            throw new MeCabInvalidFileException("dictionary file is broken", this.FileName);
        }