• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
成为自己最想成为的那种人
博客园    首页    新随笔    联系   管理    订阅  订阅
将搜索关键词加红 - 搜索引擎

加红:

        public static string ReplaceHightLight(string keyword, string content)
        {
            string keywords = "<font style=\"font-style:normal;color:#cc0000;\"><b>" + keyword + "</b></font>";
            //替换为加红的
            string result = content.Replace(keyword,keywords);

            return result;
        }

分词:

        public static string[] SplitWords(string content)
        {
            List<string> strList = new List<string>();
            Analyzer analyzer = new PanGuAnalyzer();//指定使用盘古 PanGuAnalyzer 分词算法
            TokenStream tokenStream = analyzer.TokenStream("", new StringReader(content));

            Stopwatch watch = new Stopwatch();
            watch.Start();
            Segment segment = new Segment();
            ICollection<WordInfo> words = segment.DoSegment(content);

            watch.Stop();

            foreach (WordInfo wordInfo in words)
            {
                strList.Add(wordInfo.Word);

            }

            return strList.ToArray();
        }

 

posted on 2018-03-08 09:06  遇见未来  阅读(322)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3