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是怎么分词了吧!

最新文章

  1. LinqToXml (一) Create Xml file By Dom /Linq
  2. .Net中的并行编程-3.ConcurrentQueue实现与分析
  3. 执行shell出现bad interpreter
  4. PHP基础知识2
  5. 关于shape_trans (ConnectedRegions, ConvexRegions, 'convex')的作用于对比
  6. jquery mobile cannot be created in a document with origin 'null' and URL
  7. CentOS 7 安装Docker
  8. QQ微信与智能家电连接一起 小马哥"连接一切"野心凸显
  9. PhoneGap 安装体验
  10. java JdbcTemplate源码
  11. 练习2 G题 - 数值统计
  12. Swift编程语言学习3.1排列
  13. Gink掉过的坑(一):将CCTableView导入到lua中
  14. Arduino 不同Arduino衍生板子的问题
  15. Locust no-web 模式与参数详解
  16. POJ 2195 Going Home (费用流)
  17. 201621123050 《Java程序设计》第1周学习总结
  18. static修饰符详解
  19. 结对编程项目——C语言实现WordCount Web化
  20. MySql必备技能 不会的赶紧get一下 可以说很详细了

热门文章

  1. 项目中自己觉得比较好的Erlang语法
  2. 剑指Offer - 九度1385 - 重建二叉树
  3. 《Cracking the Coding Interview》——第13章:C和C++——题目5
  4. 《Cracking the Coding Interview》——第1章:数组和字符串——题目3
  5. Lua语言中文手册 转载自网络
  6. 程序员必备PC维修法(硬件篇)
  7. Javascript在浏览器中的加载顺序详解!
  8. typeAliasesPackage 配置
  9. 解决windows文件名过长无法删除的问题
  10. hdu 1714 RedField