コード例 #1
0
ファイル: DictMatch.cs プロジェクト: yunqing-xia/AdvUtils
        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();
        }
コード例 #2
0
ファイル: DictMatch.cs プロジェクト: zhongkaifu/AdvUtils
        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
ファイル: DictMatch.cs プロジェクト: yunqing-xia/AdvUtils
        private int InsertDentry(int lastpos, int value, ref int curpos)
        {
            int tmpdepos;
            int curdepos;
            int sufpos;
            int hsize;
            int hpos;

            if (lastpos != DM_DENTRY_FIRST)
            {
                sufpos = dentry[lastpos].suffix_pos;
            }
            else
            {
                sufpos = entrance;
            }

            if (sufpos == DM_SUFENTRY_NULL)
            {
                if (seinfo.Count > sebufsize)
                {
                    if (ResizeInfo() < 0)
                    {
                        return(-1);
                    }
                }

                dentry[lastpos].suffix_pos = seinfo.Count;
                sufentry s = InitSufentry(1, lastpos);
                seinfo.Add(s);
                sufpos = dentry[lastpos].suffix_pos;
            }


            hsize    = seinfo[sufpos].hashsize;
            hpos     = value % hsize;
            tmpdepos = seinfo[sufpos].hashList[hpos];
            if ((tmpdepos != DM_DENTRY_NULL) && (dentry[tmpdepos].value == value))
            {
                curpos = tmpdepos;
                return(0);
            }
            else
            {
                dm_entry_t det = new dm_entry_t();
                det.value      = value;
                det.lemma_pos  = DM_LEMMA_NULL;
                det.suffix_pos = DM_SUFENTRY_NULL;

                curdepos = dentry.Count;
                dentry.Add(det);

                if (tmpdepos == DM_DENTRY_NULL)
                {
                    seinfo[sufpos].hashList[hpos] = curdepos;
                    curpos = curdepos;
                    return(1);
                }
                else
                {
                    int newhash;
                    for (newhash = hsize + 1; ; newhash++)
                    {
                        int conflict = 0;
                        if (seinfo.Count > sebufsize)
                        {
                            if (ResizeInfo() < 0)
                            {
                                return(-1);
                            }
                        }

                        if (lastpos != DM_DENTRY_FIRST)
                        {
                            sufpos = dentry[lastpos].suffix_pos;
                        }
                        else
                        {
                            sufpos = entrance;
                        }

                        sufentry s = InitSufentry(newhash, lastpos);
                        for (int i = 0; i < hsize; i++)
                        {
                            int others;
                            others = seinfo[sufpos].hashList[i];
                            if (others != DM_DENTRY_NULL)
                            {
                                int tmphpos;
                                tmphpos = dentry[others].value % newhash;
                                if (s.hashList[tmphpos] == DM_DENTRY_NULL)
                                {
                                    s.hashList[tmphpos] = others;
                                }
                                else
                                {
                                    conflict = 1;
                                    break;
                                }
                            }
                        }
                        if (conflict == 0)
                        {
                            int tmphpos;
                            tmphpos = dentry[curdepos].value % newhash;
                            if (s.hashList[tmphpos] == DM_DENTRY_NULL)
                            {
                                s.hashList[tmphpos] = curdepos;
                            }
                            else
                            {
                                conflict = 1;
                            }
                        }
                        if (conflict == 0)
                        {
                            if (lastpos != DM_DENTRY_FIRST)
                            {
                                dentry[lastpos].suffix_pos = seinfo.Count;
                            }
                            else
                            {
                                entrance = seinfo.Count;
                            }
                            seinfo.Add(s);
                            curpos = curdepos;
                            return(1);
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: DictMatch.cs プロジェクト: zhongkaifu/AdvUtils
        private int InsertDentry(int lastpos, int value, ref int curpos)
        {
            int tmpdepos;
            int curdepos;
            int sufpos;
            int hsize;
            int hpos;

            if (lastpos != DM_DENTRY_FIRST)
            {
                sufpos = dentry[lastpos].suffix_pos;
            }
            else
            {
                sufpos = entrance;
            }

            if (sufpos == DM_SUFENTRY_NULL)
            {
                if (seinfo.Count > sebufsize)
                {
                    if (ResizeInfo() < 0)
                    {
                        return -1;
                    }
                }

                dentry[lastpos].suffix_pos = seinfo.Count;
                sufentry s = InitSufentry(1, lastpos);
                seinfo.Add(s);
                sufpos = dentry[lastpos].suffix_pos;
            }


            hsize = seinfo[sufpos].hashsize;
            hpos = value % hsize;
            tmpdepos = seinfo[sufpos].hashList[hpos];
            if ((tmpdepos != DM_DENTRY_NULL) && (dentry[tmpdepos].value == value))
            {
                curpos = tmpdepos;
                return 0;
            }
            else
            { 
                dm_entry_t det = new dm_entry_t();
                det.value = value;
                det.lemma_pos = DM_LEMMA_NULL;
                det.suffix_pos = DM_SUFENTRY_NULL;

                curdepos = dentry.Count;
                dentry.Add(det);

                if (tmpdepos == DM_DENTRY_NULL)
                {
                    seinfo[sufpos].hashList[hpos] = curdepos;
                    curpos = curdepos;
                    return 1;
                }
                else
                {
                    int newhash;
                    for (newhash = hsize + 1; ; newhash++)
                    {
                        int conflict = 0;
                        if (seinfo.Count > sebufsize)
                        {
                            if (ResizeInfo() < 0)
                            {
                                return -1;
                            }
                        }

                        if (lastpos != DM_DENTRY_FIRST)
                        {
                            sufpos = dentry[lastpos].suffix_pos;
                        }
                        else
                        {
                            sufpos = entrance;
                        }

                        sufentry s = InitSufentry(newhash, lastpos);
                        for (int i = 0; i < hsize; i++)
                        {
                            int others;
                            others = seinfo[sufpos].hashList[i];
                            if (others != DM_DENTRY_NULL)
                            {
                                int tmphpos;
                                tmphpos = dentry[others].value % newhash;
                                if (s.hashList[tmphpos]  == DM_DENTRY_NULL)
                                {
                                    s.hashList[tmphpos] = others;
                                }
                                else
                                {
                                    conflict = 1;
                                    break;
                                }
                            }
                        }
                        if (conflict == 0)
                        {
                            int tmphpos;
                            tmphpos = dentry[curdepos].value % newhash;
                            if (s.hashList[tmphpos] == DM_DENTRY_NULL)
                            {
                                s.hashList[tmphpos] = curdepos;
                            }
                            else
                            {
                                conflict = 1;
                            }
                        }
                        if (conflict == 0)
                        {
                            if (lastpos != DM_DENTRY_FIRST)
                            {
                                dentry[lastpos].suffix_pos = seinfo.Count;
                            }
                            else
                            {
                                entrance = seinfo.Count;
                            }
                            seinfo.Add(s);
                            curpos = curdepos;
                            return 1;
                        }
                    }
                }
            }
        }