Exemple #1
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());
            }
        }
Exemple #2
0
        public void splitwords(string sentence, int weight)
        {//分词函数,对sentence进行分词,其中每个词的权重按weight计算,分出的词加入关键词列表中
            List <T_WordInfo> words = m_SimpleDictSeg.SegmentToWordInfos(sentence);

            for (int i = 0; i < words.Count; i++)
            {
                //判断文本是否进入
                if (words[i] == null)
                {
                    continue;
                }
                if (output.keywordList.ContainsKey(words[i].Word))
                {
                    output.keywordList[words[i].Word] = (int)output.keywordList[words[i].Word] + weight;
                }
                else
                {
                    output.keywordList.Add(words[i].Word, weight);
                }
            }
        }
Exemple #3
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);
        }