Example #1
0
        /// <summary>
        /// 中文分词方法
        /// </summary>
        /// <param name="text">待分词的文本</param>
        /// <returns></returns>
        public static List <string> WordSegment(string text)
        {
            if (text == null || text.Trim().Length <= 0)
            {
                return(new List <string>(0));
            }
            if (s_Segment == null)
            {
                lock (s_Seg_SyncObj)
                {
                    if (s_Segment == null)
                    {
                        string path = ConfigurationManager.AppSettings["WordSegmentConfigPath"];
                        if (path == null || path.Trim().Length <= 0)
                        {
                            // 使用默认路径
                            path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "Configuration\\KTDictSeg.config");
                        }
                        else
                        {
                            string p = Path.GetPathRoot(path);
                            if (p == null || p.Trim().Length <= 0) // 说明是相对路径
                            {
                                path = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, path);
                            }
                        }
                        CSimpleDictSeg tmp = new CSimpleDictSeg();
                        tmp.LoadConfig(path);
                        tmp.LoadDict();
                        s_Segment = tmp;
                    }
                }
            }
            List <T_WordInfo> list    = s_Segment.SegmentToWordInfos(text);
            List <string>     rstList = new List <string>(list.Count);

            foreach (T_WordInfo info in list)
            {
                if (info != null && info.Word.Length > 1)
                {
                    rstList.Add(info.Word);
                }
            }
            return(rstList);
        }
Example #2
0
        private void BigBangDemo()
        {
            if (m_SimpleDictSeg == null)
            {
                m_SimpleDictSeg = new CSimpleDictSeg();
                m_SimpleDictSeg.LoadConfig("KTDictSeg.xml");
                m_SimpleDictSeg.MatchName       = true;
                m_SimpleDictSeg.FreqFirst       = true;
                m_SimpleDictSeg.AutoStudy       = true;
                m_SimpleDictSeg.FilterStopWords = true;
                m_SimpleDictSeg.MultiSelect     = false;
                m_SimpleDictSeg.Redundancy      = 1;
                m_SimpleDictSeg.LoadDict();
            }
            List <T_WordInfo> words = m_SimpleDictSeg.SegmentToWordInfos(word);

            foreach (T_WordInfo x in words)
            {
                clbWords.Items.Add(x.ToString());
            }
        }
Example #3
0
 public void initDict()
 {
     //出事话分词词典
     m_SimpleDictSeg = new CSimpleDictSeg();
     m_SimpleDictSeg.LoadConfig("KTDictSeg.xml");
     m_SimpleDictSeg.LoadDict();
 }
Example #4
0
 public void initDict()
 {//初始化分词词典
     m_SimpleDictSeg = new CSimpleDictSeg();
     m_SimpleDictSeg.LoadConfig("KTDictSeg.xml");
     m_SimpleDictSeg.LoadDict();
 }