.net 盘古分词

需要引用:using PanGu.Lucene.Analyzer;

 下载之后有个字典包,程序运行时会提示要放到站点的bin目录下

.net 盘古分词

如果自己还想添加一些不分词的关键字,可以在Dict.dct里面添加。盘古官方给了一个工具可以添加

.net 盘古分词

sourceCode里面有程序运行一下就可以,也有说明。可在官网下载这个工具

代码:

Analyzer anal = new PanGuAnalyzer();//使用盘古分词

System.IO.StringReader reader = new System.IO.StringReader(str);//str为需要拆分的词
Lucene.Net.Analysis.TokenStream ts = anal.TokenStream("", reader);
bool hasnext = ts.IncrementToken();
List<string> list = new List<string>();
Lucene.Net.Analysis.Tokenattributes.ITermAttribute ita;
while (hasnext)
{
ita = ts.GetAttribute<Lucene.Net.Analysis.Tokenattributes.ITermAttribute>();
Console.WriteLine(ita.Term);
list.Add(ita.Term);
hasnext = ts.IncrementToken();
}
ts.CloneAttributes();
reader.Close();
anal.Close();