`

mmseg4j分词器简单实例

    博客分类:
  • JAVA
 
阅读更多
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)+"|");
}
}
}

}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics