Exemple #1
0
        public static TagSet LoadFromStream(TextModelReader sr)
        {
            string xname = sr.Read();

            if (xname != typeof(TagSet).FullName)
            {
                throw new Exception("model name does not match");
            }

            int startlvl = sr.NestLevel;

            var xver = sr.ReadOptionUInt64("VER");

            if (xver != VER)
            {
                throw new Exception("version number does not match");
            }

            var ts = new TagSet();

            ts.ROOT = sr.ReadOptionString("ROOT");

            ts.PTs = CodeBook32.LoadFromStream(sr);
            ts.NTs = CodeBook32.LoadFromStream(sr);

            xname = sr.Read();

            if(xname != typeof(TagSet).FullName || sr.NestLevel != startlvl)
            {
                throw new Exception("model name does not match");
            }

            return ts;
        }
Exemple #2
0
        public static Vocabulary LoadFromStream(TextModelReader sr)
        {
            var v = new Vocabulary();
            int knownWordCount = 0;
            int sigCount = 0;
            string name = typeof(Vocabulary).FullName;
            int startLvl = 0;

            string line = sr.Read();
            startLvl = sr.NestLevel;
            if (line != name)
            {
                throw new Exception("error in model file!");
            }

            var xsig = sr.ReadOptionUInt64("SIG");
            var xver = sr.ReadOptionUInt64("VER");
            if (xsig != SIG || xver != VER)
            {
                throw new Exception("Signiture or version does not match!");
            }
            knownWordCount = sr.ReadOptionInt("knownWordCount");
            sigCount = sr.ReadOptionInt("sigCount");
            v.vocab = CodeBook32.LoadFromStream(sr);
            v.signitureVocab = CodeBook32.LoadFromStream(sr);

            if (v.vocab.Count != knownWordCount || v.signitureVocab.Count != sigCount)
            {
                throw new Exception("vocab size does not match");
            }

            string closeline = sr.Read();

            if (sr.NestLevel != startLvl || closeline != name)
            {
                throw new Exception("model is not closed!");
            }

            return v;
        }