コード例 #1
0
        public void Load(String fileName)
        {
            try
            {
                List <T_ChsNameWordTraffic> newWords = new List <T_ChsNameWordTraffic>();

                if (!File.Exists(fileName))
                {
                    //字典文件不存在
                    return;
                }

                MemoryStream s = CFile.ReadFileToStream(fileName);
                s.Position = 0;
                object obj;
                CSerialization.DeserializeBinary(s, out obj);
                _Traffic = (T_ChsNameTraffic)obj;

                _Traffic.AfterCount      = 0;
                _Traffic.AfterWordCount  = 0;
                _Traffic.BeforeCount     = 0;
                _Traffic.BeforeWordCount = 0;

                //整理姓名前缀后缀表
                foreach (T_ChsNameWordTraffic wordTraffic in _Traffic.Words)
                {
                    if (wordTraffic.Word.Length > 1)
                    {
                        if (wordTraffic.Word[0] >= 0x4e00 && wordTraffic.Word[0] <= 0x9fa5)
                        {
                            //是汉字,且长度大于2,才作为有效前后缀
                            newWords.Add(wordTraffic);

                            if (wordTraffic.After > 0)
                            {
                                _Traffic.AfterCount += wordTraffic.After;
                                _Traffic.AfterWordCount++;
                            }

                            if (wordTraffic.Before > 0)
                            {
                                _Traffic.BeforeCount += wordTraffic.After;
                                _Traffic.BeforeWordCount++;
                            }
                        }
                    }
                }

                _Traffic.Words = newWords;
            }
            catch
            {
                _Traffic = new T_ChsNameTraffic();
            }

            foreach (T_ChsNameWordTraffic wordTraffic in _Traffic.Words)
            {
                _Table[wordTraffic.Word] = wordTraffic;
            }
        }
コード例 #2
0
        static public T_DictFile LoadFromBinFile(String fileName)
        {
            MemoryStream s = CFile.ReadFileToStream(fileName);

            s.Position = 0;
            object obj;

            CSerialization.DeserializeBinary(s, out obj);
            return((T_DictFile)obj);
        }