Ejemplo n.º 1
0
        /// <summary>
        /// 输出词列表
        /// </summary>
        private void OutWords()
        {
            IDictionaryEnumerator idEnumerator1 = _htWords.GetEnumerator();

            while (idEnumerator1.MoveNext())
            {
                IDictionaryEnumerator idEnumerator2 = ((Hashtable)idEnumerator1.Value).GetEnumerator();
                while (idEnumerator2.MoveNext())
                {
                    SplitList aa = (SplitList)idEnumerator2.Value;
                    for (int i = 0; i < aa.Count; i++)
                    {
                        Console.WriteLine(idEnumerator1.Key.ToString()
                                          + idEnumerator2.Key.ToString() + aa.GetElem(i).ToString());
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 按长度排序
        /// </summary>
        /// <param name="list"></param>
        public void Sort(SplitList list)
        {
            int max = 0;

            for (int i = 0; i < list.Count - 1; ++i)
            {
                max = i;
                for (int j = i + 1; j < list.Count; ++j)
                {
                    string str1 = list.GetElem(j).ToString();
                    string str2 = list.GetElem(max).ToString();
                    int    l1;
                    int    l2;
                    if (str1 == "null")
                    {
                        l1 = 0;
                    }
                    else
                    {
                        l1 = str1.Length;
                    }

                    if (str2 == "null")
                    {
                        l2 = 0;
                    }
                    else
                    {
                        l2 = str2.Length;
                    }

                    if (l1 > l2)
                    {
                        max = j;
                    }
                }
                object o = list.GetElem(max);
                list.SetElem(max, list.GetElem(i));
                list.SetElem(i, o);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 对加载的词典排序并重新写入
        /// </summary>
        /// <param name="Reload">是否重新加载</param>
        private void SortDic(bool Reload)
        {
            DateTime     start = DateTime.Now;
            StreamWriter sw    = new StreamWriter(DicPath, false, System.Text.Encoding.UTF8);

            IDictionaryEnumerator idEnumerator1 = _htWords.GetEnumerator();

            while (idEnumerator1.MoveNext())
            {
                IDictionaryEnumerator idEnumerator2 = ((Hashtable)idEnumerator1.Value).GetEnumerator();
                while (idEnumerator2.MoveNext())
                {
                    SplitList aa = (SplitList)idEnumerator2.Value;
                    aa.Sort();
                    for (int i = 0; i < aa.Count; i++)
                    {
                        if (aa.GetElem(i).ToString() == "null")
                        {
                            sw.WriteLine(idEnumerator1.Key.ToString() + idEnumerator2.Key.ToString());
                        }
                        else
                        {
                            sw.WriteLine(idEnumerator1.Key.ToString()
                                         + idEnumerator2.Key.ToString() + aa.GetElem(i).ToString());
                        }
                    }
                }
            }
            sw.Close();

            //重新加载
            if (Reload)
            {
                InitWordDics();
            }

            TimeSpan duration = DateTime.Now - start;

            _mEventTime = duration.TotalMilliseconds;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 加载词列表
        /// </summary>
        private void InitWordDics()
        {
            //DateTime start = DateTime.Now;

            _htWords = new Hashtable();
            string strChar1;
            string strChar2;

            //Console.WriteLine(strDicPath);

            // StreamReader reader = new StreamReader(DicPath, System.Text.Encoding.UTF8);
            //string strline = reader.ReadLine();

            string[]  myStri = DicPath.Split('_');
            Hashtable father = _htWords;

            Hashtable child     = new Hashtable();
            Hashtable forfather = _htWords;
            SplitList list;
            long      i       = 0;
            string    strline = myStri[0];

            while (strline != null && strline.Trim() != "")
            {
                i++;

                strChar1 = strline.Substring(0, 1);
                strChar2 = strline.Substring(1, 1);
                if (!_htWords.ContainsKey(strChar1))
                {
                    father = new Hashtable();
                    _htWords.Add(strChar1, father);
                }
                else
                {
                    father = (Hashtable)_htWords[strChar1];
                }

                if (!father.ContainsKey(strChar2))
                {
                    list = new SplitList();
                    if (strline.Length > 2)
                    {
                        list.Add(strline.Substring(2));
                    }
                    else
                    {
                        list.Add("null");
                    }
                    father.Add(strChar2, list);
                }
                else
                {
                    list = (SplitList)father[strChar2];
                    if (strline.Length > 2)
                    {
                        list.Add(strline.Substring(2));
                    }
                    else
                    {
                        list.Add("null");
                    }
                    father[strChar2] = list;
                }
                _htWords[strChar1] = father;



                strline = myStri[i];
            }
            try
            {
                // reader.Close();
            }
            catch
            { }

            _alNoise  = LoadWords(NoisePath, _alNoise);
            _alNumber = LoadWords(NumberPath, _alNumber);
            _alWord   = LoadWords(WordPath, _alWord);
            _alPrefix = LoadWords(PrefixPath, _alPrefix);
            //alPrefix = new ArrayList() ;

            // TimeSpan duration = DateTime.Now - start;

            // m_EventTime = duration.TotalMilliseconds;
            //			Console.WriteLine("加载时间:" + duration.TotalMilliseconds);
            //			Console.WriteLine(this.htWords.Count) ;
            //			Console.WriteLine(length) ;
            //OutWords();
            //outNumbers();
        }