⑴ 如何使用中科院分词系统java版
1、官网下载最新版本分词器
注:听学长说这个分词器有时间限制,所以一段时间之后需要重新下载。
2、将下载的ICTCLAS50_Windows_32_JNI.rar解压,其中有API,Demo,Doc,Sample四个文件夹;
API文件夹中的东西就是我们需要使用的。
⑵ java 中文分词为什么用 ik
为什么呢?因为Lucene自带的分词器比较适合英文的分词,而IK首先是一个中文的分词器。
具体的优点先不细说,单说分词的结果来看:
1 比如说 我爱北京
使用自带的分词 我/爱/北/京
IK分词 我/爱/北京
2 可以自己扩展词典
有很多分词器是不能够进行自己扩展词典的,有自己的词典,导致分词的结果才是自己想要的结果。
3 可以自己定义停用词字典
4 和Lucene结合比较高,有很多封装好的模块。用来检索非常顺手。
当然,IK自2012年已经不再维护了。后面有出现了很多其他的分词器。
⑶ 谁来推荐一个JAVA的分词工具
java读取中文分词工具:linger
Java开源中文分词器
1、word分词器
2、Ansj分词器
3、Stanford分词器
4、FudanNLP分词器
5、Jieba分词器
6、Jcseg分词器
7、MMSeg4j分词器
8、IKAnalyzer分词器
9、Paoding分词器
10、smartcn分词器
⑷ java 怎么用lucenes进行分词
import java.io.IOException;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.StringField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
import org.wltea.analyzer.lucene.IKAnalyzer;
/**
* 使用IKAnalyzer进行Lucene索引和查询的演示
* 2012-3-2
*
* 以下是结合Lucene4.0 API的写法
*
*/
public class LuceneIndexAndSearchDemo {
/**
* 模拟:
* 创建一个单条记录的索引,并对其进行搜索
* @param args
*/
public static void main(String[] args){
//Lucene Document的域名
String fieldName = "text";
//检索内容
String text = "IK Analyzer是一个结合词典分词和文法分词的中文分词开源工具包。它使用了全新的正向迭代最细粒度切分算法。";
//实例化IKAnalyzer分词器
Analyzer analyzer = new IKAnalyzer(true);
Directory directory = null;
IndexWriter iwriter = null;
IndexReader ireader = null;
IndexSearcher isearcher = null;
try {
//建立内存索引对象
directory = new RAMDirectory();
//配置IndexWriterConfig
IndexWriterConfig iwConfig = new IndexWriterConfig(Version.LUCENE_40 , analyzer);
iwConfig.setOpenMode(OpenMode.CREATE_OR_APPEND);
iwriter = new IndexWriter(directory , iwConfig);
//写入索引
Document doc = new Document();
doc.add(new StringField("ID", "10000", Field.Store.YES));
doc.add(new TextField(fieldName, text, Field.Store.YES));
iwriter.addDocument(doc);
iwriter.close();
//搜索过程**********************************
//实例化搜索器
ireader = DirectoryReader.open(directory);
isearcher = new IndexSearcher(ireader);
String keyword = "中文分词工具包";
//使用QueryParser查询分析器构造Query对象
QueryParser qp = new QueryParser(Version.LUCENE_40, fieldName, analyzer);
qp.setDefaultOperator(QueryParser.AND_OPERATOR);
Query query = qp.parse(keyword);
System.out.println("Query = " + query);
//搜索相似度最高的5条记录
TopDocs topDocs = isearcher.search(query , 5);
System.out.println("命中:" + topDocs.totalHits);
//输出结果
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
for (int i = 0; i < topDocs.totalHits; i++){
Document targetDoc = isearcher.doc(scoreDocs[i].doc);
System.out.println("内容:" + targetDoc.toString());
}
} catch (CorruptIndexException e) {
e.printStackTrace();
} catch (LockObtainFailedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
} finally{
if(ireader != null){
try {
ireader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(directory != null){
try {
directory.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
⑸ java word分词器怎样安装在java中
word分词是一个Java实现的分布式的中文分词组件,提供了多种基于词典的分词算法,并利用ngram模型来消除歧义。
如果需要安装word分词器可以参考下面的步骤:
JDK官网:http://www.oracle.com/technetwork/java/javase/downloads/index.html
Eclipse官网:http://www.eclipse.org
打开word分词器的官方github主页:https://github.com/ysc/word
导入成功之后就可以在自己的项目中使用word分词器了。
⑹ 汉语句子拆分算法 java实现 高手请指教
/*实现单个拆开*/
package dd;
public class Dd {
public static void main(String[] args) {
String kissi="今天,天气比较好";
//将字符串拆成一个char[]数组
//至于tochararray(),请查帮助文档
char[] kiss=kissi.toCharArray();
for(int i=0;i<kiss.length;i++){
System.out.println(kiss[i]);
}
}
}
⑺ java中文分词组件word怎么使用
参考如下
1、快速体验
运行项目根目录下的脚本demo-word.bat可以快速体验分词效果
用法: command [text] [input] [output]
命令command的可选值为:demo、text、file
demo
text 杨尚川是APDPlat应用级产品开发平台的作者
file d:/text.txt d:/word.txt
exit
2、对文本进行分词
移除停用词:List<Word> words = WordSegmenter.seg("杨尚川是APDPlat应用级产品开发平台的作者");
保留停用词:List<Word> words = WordSegmenter.segWithStopWords("杨尚川是APDPlat应用级产品开发平台的作者");
System.out.println(words);
输出:
移除停用词:[杨尚川, apdplat, 应用级, 产品, 开发平台, 作者]
保留停用词:[杨尚川, 是, apdplat, 应用级, 产品, 开发平台, 的, 作者]
3、对文件进行分词
String input = "d:/text.txt";
String output = "d:/word.txt";
移除停用词:WordSegmenter.seg(new File(input), new File(output));
保留停用词:WordSegmenter.segWithStopWords(new File(input), new File(output));
4、自定义配置文件
默认配置文件为类路径下的word.conf,打包在word-x.x.jar中
自定义配置文件为类路径下的word.local.conf,需要用户自己提供
如果自定义配置和默认配置相同,自定义配置会覆盖默认配置
配置文件编码为UTF-8
5、自定义用户词库
自定义用户词库为一个或多个文件夹或文件,可以使用绝对路径或相对路径
用户词库由多个词典文件组成,文件编码为UTF-8
词典文件的格式为文本文件,一行代表一个词
可以通过系统属性或配置文件的方式来指定路径,多个路径之间用逗号分隔开
类路径下的词典文件,需要在相对路径前加入前缀classpath:
指定方式有三种:
指定方式一,编程指定(高优先级):
WordConfTools.set("dic.path", "classpath:dic.txt,d:/custom_dic");
DictionaryFactory.reload();//更改词典路径之后,重新加载词典
指定方式二,Java虚拟机启动参数(中优先级):
java -Ddic.path=classpath:dic.txt,d:/custom_dic
指定方式三,配置文件指定(低优先级):
使用类路径下的文件word.local.conf来指定配置信息
dic.path=classpath:dic.txt,d:/custom_dic
如未指定,则默认使用类路径下的dic.txt词典文件
6、自定义停用词词库
使用方式和自定义用户词库类似,配置项为:
stopwords.path=classpath:stopwords.txt,d:/custom_stopwords_dic
7、自动检测词库变化
可以自动检测自定义用户词库和自定义停用词词库的变化
包含类路径下的文件和文件夹、非类路径下的绝对路径和相对路径
如:
classpath:dic.txt,classpath:custom_dic_dir,
d:/dic_more.txt,d:/DIC_DIR,D:/DIC2_DIR,my_dic_dir,my_dic_file.txt
classpath:stopwords.txt,classpath:custom_stopwords_dic_dir,
d:/stopwords_more.txt,d:/STOPWORDS_DIR,d:/STOPWORDS2_DIR,stopwords_dir,remove.txt
8、显式指定分词算法
对文本进行分词时,可显式指定特定的分词算法,如:
WordSegmenter.seg("APDPlat应用级产品开发平台", SegmentationAlgorithm.BidirectionalMaximumMatching);
SegmentationAlgorithm的可选类型为:
正向最大匹配算法:MaximumMatching
逆向最大匹配算法:ReverseMaximumMatching
正向最小匹配算法:MinimumMatching
逆向最小匹配算法:ReverseMinimumMatching
双向最大匹配算法:BidirectionalMaximumMatching
双向最小匹配算法:BidirectionalMinimumMatching
双向最大最小匹配算法:
全切分算法:FullSegmentation
最少分词算法:MinimalWordCount
最大Ngram分值算法:MaxNgramScore
9、分词效果评估
运行项目根目录下的脚本evaluation.bat可以对分词效果进行评估
评估采用的测试文本有253 3709行,共2837 4490个字符
评估结果位于target/evaluation目录下:
corpus-text.txt为分好词的人工标注文本,词之间以空格分隔
test-text.txt为测试文本,是把corpus-text.txt以标点符号分隔为多行的结果
standard-text.txt为测试文本对应的人工标注文本,作为分词是否正确的标准
result-text-***.txt,***为各种分词算法名称,这是word分词结果
perfect-result-***.txt,***为各种分词算法名称,这是分词结果和人工标注标准完全一致的文本
wrong-result-***.txt,***为各种分词算法名称,这是分词结果和人工标注标准不一致的文本
⑻ java jieba分词怎么用
网页链接这个网站
成功了,可喜可贺。
⑼ 求高手给我用java编写一个英文单词分词器
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Danci {
public static void main(String[] args){
String str = new String();
System.out.print("请输入一个英文句子:");
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));//获取键盘输入
str = br.readLine();
}catch(IOException e){
e.printStackTrace();
}
String []s = str.split(" ");//转换成数组
System.out.println("你输入的句子共有单词 "+s.length+" 个");//s.length获取数组长度
}
}
//此程序只能获取一句话的单词个数.
⑽ java英文分词工具
Notepad++ 和 Editplus 都是开发常用的进行代码文本化编辑工具,eclipse、Myeclipse、IDE等都是常用的集成开发环境,可以对代码进行编辑,有各种提示,希望能帮助你