第四步:查看StandardAnalyzer的分词效果并添加停用词
2024-09-04 18:21:08
LUCENE的创建索引有好多种分词方式,这里我们用的StandardAnalyzer分词
package cn.lucene; import java.io.IOException; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.util.CharArraySet; public class test1 {
public static final String[] china_stop = {"着", "的", "之", "式"};
public static void main(String[] args) throws IOException {
//把数组赋值到CharArraySet里
CharArraySet cnstop=new CharArraySet(china_stop.length, true);
for(String value : china_stop) {
cnstop.add(value);
}
//并把StandardAnalyzer默认的停用词加进来
cnstop.addAll(StandardAnalyzer.STOP_WORDS_SET);
System.out.println(cnstop); Analyzer analyzer = new StandardAnalyzer(cnstop);
TokenStream stream= analyzer.tokenStream("", "中秋be之夜,享受着月华的孤独,享受着爆炸式的思维跃迁");
//获取每个单词信息,获取词元文本属性
CharTermAttribute cta = stream.addAttribute(CharTermAttribute.class);
stream.reset();
while(stream.incrementToken()){
System.out.print("[" + cta + "]");
}
System.out.println();
analyzer.close();
}
}
输出结果如下:
输入所有的停止词,可以看到新的停止词已经加进去了
[着, but, be, 的, with, such, then, for, 之, 式, no, will, not, are, and, their, if, this, on, into, a, or, there, in, that, they, was, is, it, an, the, as, at, of, by, to, these]
分词结果,"着", "的", "之", "式"四个词已经被停止分词了
[中][秋][夜][享][受][月][华][孤][独][享][受][爆][炸][思][维][跃][迁]
通过上面的分词效果应该就知道StandardAnalyzer是怎么分词了吧!
最新文章
- LinqToXml (一) Create Xml file By Dom /Linq
- .Net中的并行编程-3.ConcurrentQueue实现与分析
- 执行shell出现bad interpreter
- PHP基础知识2
- 关于shape_trans (ConnectedRegions, ConvexRegions, 'convex')的作用于对比
- jquery mobile cannot be created in a document with origin 'null' and URL
- CentOS 7 安装Docker
- QQ微信与智能家电连接一起 小马哥";连接一切";野心凸显
- PhoneGap 安装体验
- java JdbcTemplate源码
- 练习2 G题 - 数值统计
- Swift编程语言学习3.1排列
- Gink掉过的坑(一):将CCTableView导入到lua中
- Arduino 不同Arduino衍生板子的问题
- Locust no-web 模式与参数详解
- POJ 2195 Going Home (费用流)
- 201621123050 《Java程序设计》第1周学习总结
- static修饰符详解
- 结对编程项目——C语言实现WordCount Web化
- MySql必备技能 不会的赶紧get一下 可以说很详细了