加红:
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(); }