import java.io.IOException;
import java.io.StringReader;
import com.chenlb.mmseg4j.Chunk;
import com.chenlb.mmseg4j.ComplexSeg;
import com.chenlb.mmseg4j.Dictionary;
import com.chenlb.mmseg4j.MMSeg;
import com.chenlb.mmseg4j.Seg;
import com.chenlb.mmseg4j.SimpleSeg;
public class TestFenCi{
public static void main(String[] args) throws IOException{
String txt = "";
txt = "我是中国人。";
Dictionary dic = new Dictionary();
Seg seg = null;
// seg = new SimpleSeg(dic);
seg = new ComplexSeg(dic);
MMSeg mmSeg = new MMSeg(new StringReader(txt), seg);
Chunk chunk = null;
while((chunk=mmSeg.next())!=null) {
for(char[] word : chunk.getWords()) {
if(word != null) {
System.out.print(new String(word)+"|");
}
}
}
}
}
import java.io.StringReader;
import com.chenlb.mmseg4j.Chunk;
import com.chenlb.mmseg4j.ComplexSeg;
import com.chenlb.mmseg4j.Dictionary;
import com.chenlb.mmseg4j.MMSeg;
import com.chenlb.mmseg4j.Seg;
import com.chenlb.mmseg4j.SimpleSeg;
public class TestFenCi{
public static void main(String[] args) throws IOException{
String txt = "";
txt = "我是中国人。";
Dictionary dic = new Dictionary();
Seg seg = null;
// seg = new SimpleSeg(dic);
seg = new ComplexSeg(dic);
MMSeg mmSeg = new MMSeg(new StringReader(txt), seg);
Chunk chunk = null;
while((chunk=mmSeg.next())!=null) {
for(char[] word : chunk.getWords()) {
if(word != null) {
System.out.print(new String(word)+"|");
}
}
}
}
}
本文介绍了一个基于Java实现的中文分词工具MMSeg4J的使用示例,展示了如何加载字典、选择不同的分词算法并进行分词操作。此工具能够帮助开发者快速地对中文文本进行精确的词汇切分。
1239

被折叠的 条评论
为什么被折叠?



