예제 #1
0
        private int AddLemma(string strTerm, string strProp)
        {
            int curpos     = 0;
            int last_depos = DM_DENTRY_FIRST;
            int cur_depos  = DM_COMMON_NULL;
            int value      = 0;
            int lmpos      = DM_COMMON_NULL;

            //Check if lemma has already in the dictionary
            if ((lmpos = SeekLemma(strTerm)) == DM_LEMMA_NULL)
            {
                //new lemma, insert it into the dictionary
                while (curpos < strTerm.Length)
                {
                    value = strTerm[curpos];
                    curpos++;
                    if (InsertDentry(last_depos, value, ref cur_depos) < 0)
                    {
                        return(-1);
                    }
                    last_depos = cur_depos;
                }

                dentry[cur_depos].lemma_pos = lmlist.Count;

                Lemma lm = new Lemma();
                lm.strProp = strProp;
                lm.len     = (uint)strTerm.Length;

                lmlist.Add(lm);

                return(1);
            }
            return(0);
        }
예제 #2
0
        public void LoadDictFromBinary(string strFileName)
        {
            StreamReader sr = new StreamReader(strFileName);
            BinaryReader br = new BinaryReader(sr.BaseStream);

            dentry = new List <dm_entry_t>();
            seinfo = new List <sufentry>();
            lmlist = new List <Lemma>();

            entrance = br.ReadInt32();

            int dentryCount = br.ReadInt32();

            for (int i = 0; i < dentryCount; i++)
            {
                dm_entry_t entry = new dm_entry_t();
                entry.lemma_pos  = br.ReadInt32();
                entry.suffix_pos = br.ReadInt32();
                entry.value      = br.ReadInt32();

                dentry.Add(entry);
            }

            int seinfoCount = br.ReadInt32();

            for (int i = 0; i < seinfoCount; i++)
            {
                sufentry suf = new sufentry();
                suf.backsepos = br.ReadInt32();
                suf.hashsize  = br.ReadInt32();

                suf.hashList = new int[suf.hashsize];
                for (int j = 0; j < suf.hashsize; j++)
                {
                    suf.hashList[j] = br.ReadInt32();
                }

                seinfo.Add(suf);
            }

            sebufsize = br.ReadInt32();

            int lmlistCount = br.ReadInt32();

            for (int i = 0; i < lmlistCount; i++)
            {
                Lemma lemma = new Lemma();
                lemma.len     = br.ReadUInt32();
                lemma.strProp = br.ReadString();

                lmlist.Add(lemma);
            }

            br.Close();
        }
예제 #3
0
        public void LoadDictFromBinary(string strFileName)
        {
            StreamReader sr = new StreamReader(strFileName);
            BinaryReader br = new BinaryReader(sr.BaseStream);

            dentry = new List<dm_entry_t>();
            seinfo = new List<sufentry>();
            lmlist = new List<Lemma>();

            entrance = br.ReadInt32();

            int dentryCount = br.ReadInt32();
            for (int i = 0; i < dentryCount; i++)
            {
                dm_entry_t entry = new dm_entry_t();
                entry.lemma_pos = br.ReadInt32();
                entry.suffix_pos = br.ReadInt32();
                entry.value = br.ReadInt32();

                dentry.Add(entry);
            }

            int seinfoCount = br.ReadInt32();
            for (int i = 0; i < seinfoCount; i++)
            {
                sufentry suf = new sufentry();
                suf.backsepos = br.ReadInt32();
                suf.hashsize = br.ReadInt32();

                suf.hashList = new int[suf.hashsize];
                for (int j = 0; j < suf.hashsize; j++)
                {
                    suf.hashList[j] = br.ReadInt32();
                }

                seinfo.Add(suf);
            }

            sebufsize = br.ReadInt32();

            int lmlistCount = br.ReadInt32();
            for (int i = 0; i < lmlistCount; i++)
            {
                Lemma lemma = new Lemma();
                lemma.len = br.ReadUInt32();
                lemma.strProp = br.ReadString();

                lmlist.Add(lemma);
            }

            br.Close();
        }
예제 #4
0
        private int AddLemma(string strTerm, string strProp)
        {
            int curpos = 0;
            int last_depos = DM_DENTRY_FIRST;
            int cur_depos = DM_COMMON_NULL;
            int value = 0;
            int lmpos = DM_COMMON_NULL;

            //Check if lemma has already in the dictionary
            if ((lmpos = SeekLemma(strTerm)) == DM_LEMMA_NULL)
            {
                //new lemma, insert it into the dictionary
                while (curpos < strTerm.Length)
                {
                    value = strTerm[curpos];
                    curpos++;
                    if (InsertDentry(last_depos, value, ref cur_depos) < 0)
                    {
                        return -1;
                    }
                    last_depos = cur_depos;
                }

                dentry[cur_depos].lemma_pos = lmlist.Count;

                Lemma lm = new Lemma();
                lm.strProp = strProp;
                lm.len = (uint)strTerm.Length;

                lmlist.Add(lm);

                return 1;
            }
            return 0;
        }