JE分词器的小测试
来源:互联网 发布:seo目前发展怎么样 编辑:程序博客网 时间:2024/04/29 03:11
完全用java写的一套分词器,所以对java的支持也很好。用CLucene的话还是中科院的分词比较好。它是写成dll的文件,可以直接使用。
下面对je分词器进行简单的使用和熟悉。
package yixiaoyang;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.StringReader;
import org.apache.lucene.analysis.*;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import jeasy.analysis.*;
/*
* @param args
* @author Yi Xiaoyang
* @date 2010.2.25
* @note test the analyzer o f search engine
* using the package: lucene-core-2.4.1.jar
*/
public class analyzerTest {
public static String getContent(){
String content = "";
String msg = null;
BufferedReader buffer_reader;
// 读取文件到串供分析
File file = new File("e:/test/test.txt");
try{
// 获取文件内容
buffer_reader = new BufferedReader(new FileReader(file));
msg = buffer_reader.readLine();
while(msg != null){
content = content + msg;
msg = buffer_reader.readLine();
}
}catch(Exception e){
System.out.print("error at getContent");
e.printStackTrace();
}
return content;
}
public static void main(String[] args) {
String msg = null;
String content = getContent();
try
{
// 对文本进行分词
StringReader reader = new StringReader(content);
// 创建一个分析器
// 下面使用lucene自带的标准分词器分析
// Analyzer analyzer = new StandardAnalyzer();
// 下面是用WhitespaceAnalyzer分析器分析
// Analyzer analyzer = new WhitespaceAnalyzer();
// 下面用到je分次器分析结果
Analyzer analyzer = new MMAnalyzer();
// 获取到TokenSream对象,分析器在这一步工作贮备返回结果
TokenStream token_stream = analyzer.tokenStream("", reader);
// 开始工作
Token t = null;
System.out.println("下面打印分词结果:");
// 将分词结果写进文件
File save_file = new File("e:/test/tokenFile.txt");
DataOutputStream data_out = new DataOutputStream(new FileOutputStream(save_file));
if(save_file.exists()){
save_file.delete();
}
save_file.createNewFile();
int count = 10;
while( (t = token_stream.next()) != null )
{
// 打印分词结果
msg = t.termText();
data_out.writeChars( msg + " | ");
System.out.print(msg + " | ");
if( ( count--) < 0 )
{
System.out.print("/n");
count = 10;
}
}
System.out.println("分词打印完毕!");
data_out.close();
}
catch (Exception e) {
System.out.println("File read error!");
e.printStackTrace();
}
}
}
屏幕剪辑的捕获时间: 2010-2-26 11:24
因为是古文,分次起来较为困难。
看一下百话文的分次小效果。
屏幕剪辑的捕获时间: 2010-2-26 11:29
看起来还算不错。不过还有个别stopword还没有过滤掉。
je分词有添加新词的功能,在实际开发中可以用到相关的特性。
- JE分词器的小测试
- JE分词器
- Nutch1.2添加JE分词器
- nutch-JE分词
- lucene-JE中文分词
- 分词器的测试
- je-analysis-1.4.0中文分词添加自己的词库
- Nutch 1.0添加JE中文分词 要修改的几处地方说明
- Lucene中文分词组件JE-Analysis1.4.0
- Lucene中文分词组件 JE-Analysis
- JE分词组件,词典编辑方法
- lucene入门-使用JE中文分词
- 为Nutch 1.0添加JE中文分词
- lucene入门-使用JE中文分词
- 为Nutch 1.0添加JE中文分词
- nutch0.9中使用je分词
- 为Nutch 1.0添加JE中文分词
- Lucene分词器测试
- 超级链接
- Linux 文件特殊权限 Sticky Bit
- 十个漂亮的社交网络图标
- linux下 解压 tar 命令
- 接手别人项目,自己的心得。
- JE分词器的小测试
- [转载]用IO完成端口提高读写速度的探讨试验
- Exif格式分析
- alibaba上 IPTV STB产品分析
- cq40-612
- 经典SQL语句大全
- DIV实现滚动条
- js
- 列表标签