導航:首頁 > 編程語言 > java分詞工具

java分詞工具

發布時間:2022-06-20 15:31:49

⑴ 如何使用中科院分詞系統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分詞器可以參考下面的步驟:

1、確保電腦上已經安裝了JDK軟體和Eclispe工具,沒有安裝的可以到對應的官網下載安裝:

JDK官網:http://www.oracle.com/technetwork/java/javase/downloads/index.html

Eclipse官網:http://www.eclipse.org

2、下載word分詞器的相關jar包:

打開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等都是常用的集成開發環境,可以對代碼進行編輯,有各種提示,希望能幫助你

閱讀全文

與java分詞工具相關的資料

熱點內容
怎麼把百度雲資源壓縮 瀏覽:456
不會數學英語如何編程 瀏覽:88
如何能知道網站伺服器地址 瀏覽:648
程序員月薪5萬難嗎 瀏覽:138
如何評價程序員 瀏覽:803
雲虛機和伺服器的區別 瀏覽:403
廣西柳州壓縮機廠 瀏覽:639
arm開發編譯器 瀏覽:833
51單片機的核心 瀏覽:746
看電視直播是哪個app 瀏覽:958
將c源程序編譯成目標文件 瀏覽:787
再要你命3000pdf 瀏覽:558
ai軟體解壓軟體怎麼解壓 瀏覽:520
文件夾怎樣設置序列號 瀏覽:963
javascriptgzip壓縮 瀏覽:248
易語言怎麼取出文件夾 瀏覽:819
蘋果xs手機加密app哪裡設置 瀏覽:605
超聲霧化器與壓縮霧化器 瀏覽:643
模擬實現進程調度演算法 瀏覽:388
現在的壓縮包都是加密 瀏覽:331