Пример #1
0
        /// <summary>
        /// 构造一棵词库的树
        /// </summary>
        /// <param name="wlList"></param>
        /// <returns></returns>
        private TouchPalChar BuildTree(WordLibraryList wlList)
        {
            //先对词库进行排序再生成词库树
            wlList.Sort((a, b) => a.Word.CompareTo(b.Word));
            WordLibrary  rootWL   = wlList[0];
            var          rootChar = new TouchPalChar(); //这个只是一个根Char,没有实际的字
            TouchPalChar lastChar = AddWordLink2Char(rootChar, rootWL, 0);


            for (int i = 1; i < wlList.Count; i++)
            {
                WordLibrary wl = wlList[i];
                wl.Count = 96; //默认是96的词频
                string a   = lastChar.Word.ChineseWord;
                string b   = wl.Word;
                int    len = FindSameWordLen(a, b);
                if (len == 0)
                {
                    lastChar = AddWordLink2Char(rootChar, wl, 0);
                }
                else
                {
                    lastChar = AddWordLink2Char(lastChar, wl, len);
                }
            }
            return(rootChar);
        }
Пример #2
0
        /// <summary>
        /// 构造一棵词库的树
        /// </summary>
        /// <param name="wlList"></param>
        /// <returns></returns>
        private TouchPalChar BuildTree(WordLibraryList wlList)
        {
            //先对词库进行排序再生成词库树
            wlList.Sort((a, b) => a.Word.CompareTo(b.Word));
            WordLibrary rootWL = wlList[0];
            var rootChar = new TouchPalChar(); //这个只是一个根Char,没有实际的字
            TouchPalChar lastChar = AddWordLink2Char(rootChar, rootWL, 0);


            for (int i = 1; i < wlList.Count; i++)
            {
                WordLibrary wl = wlList[i];
                wl.Count = 96; //默认是96的词频
                string a = lastChar.Word.ChineseWord;
                string b = wl.Word;
                int len = FindSameWordLen(a, b);
                if (len == 0)
                {
                    lastChar = AddWordLink2Char(rootChar, wl, 0);
                }
                else
                {
                    lastChar = AddWordLink2Char(lastChar, wl, len);
                }
            }
            return rootChar;
        }
 public WordLibraryList Filter(WordLibraryList list)
 {
     if (Percentage == 100)
     {
         return list;
     }
     int count = list.Count*Percentage/100;
     list.Sort((a, b) => a.Rank - b.Rank);
     var result = new WordLibraryList();
     for (int i = 0; i < count; i++)
     {
         result.Add(list[i]);
     }
     return result;
 }
        public WordLibraryList Filter(WordLibraryList list)
        {
            if (Percentage == 100)
            {
                return(list);
            }
            int count = list.Count * Percentage / 100;

            list.Sort((a, b) => a.Rank - b.Rank);
            var result = new WordLibraryList();

            for (int i = 0; i < count; i++)
            {
                result.Add(list[i]);
            }
            return(result);
        }