下面是调用 GetTokenStream 的代码,请问如何从 tokenStream 中获取分词列表?
Analyzer analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48);
using TokenStream tokenStream = analyzer.GetTokenStream(null, new StringReader(phrase));
通过下面的代码实现了
Analyzer analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48);
using TokenStream tokenStream = analyzer.GetTokenStream(null, new StringReader(phrase));
ICharTermAttribute charTermAttribute = tokenStream.AddAttribute<ICharTermAttribute>();
tokenStream.Reset();
var tokeList = new List<string>();
while (tokenStream.IncrementToken())
{
tokeList.Add(charTermAttribute.ToString());
}
tokenStream.End();
Console.Write(string.Join(",", tokeList));