Beispiel #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);
                m_Traffic = (T_ChsNameTraffic)obj;

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

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

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

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

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

            foreach (T_ChsNameWordTraffic wordTraffic in m_Traffic.Words)
            {
                m_Table[wordTraffic.Word] = wordTraffic;
            }
        }
Beispiel #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);
        }