环境搭建比FNLP的简单,具体参考:https://github.com/hankcs/HanLPjava
各个版本的下载:https://github.com/hankcs/HanLP/releasesgit
完毕后有一个报错:github
字符类型对应表加载失败:eclipse
D:/eclipse_workspace/HanLPTest/HanLP/data/dictionary//other/CharType.dat.yes工具
直接在 D:/eclipse_workspace/HanLPTest/HanLP/data/dictionary//other/ 目录下新建一个txt文档将名称改成 CharType.dat.yes 便可。学习
相对比较简单。spa
尝试HanLP主要处于各个开源天然语言处理工具包之间的差别,寻找一个适合学习的开源工具包。blog
HanLP调用方法接口
HanLP几乎全部的功能均可以经过工具类HanLP快捷调用,当你想不起来调用方法时,只需键入HanLP.,IDE应当会给出提示,并展现HanLP完善的文档。全部Demo都位于com.hankcs.demo下,比文档覆盖了更多细节,更新更及时,强烈建议运行一遍。ip
HanLP的适用过程当中注意的问题:
一、由于HanLP版本更新比较频繁,因此,jar源代码版本须要对应适用,不然源码和jar中接口调用对应不上。
在进行CRF分词过程当中报错:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57)
at java.nio.ByteBuffer.allocate(ByteBuffer.java:335)
at com.hankcs.hanlp.corpus.io.IOUtil.readBytesFromFileInputStream(IOUtil.java:251)
at com.hankcs.hanlp.corpus.io.IOUtil.readBytes(IOUtil.java:178)
at com.hankcs.hanlp.corpus.io.ByteArray.createByteArray(ByteArray.java:47)
at com.hankcs.hanlp.model.crf.CRFModel.loadTxt(CRFModel.java:89)
at com.hankcs.hanlp.seg.CRF.CRFSegment.<init>(CRFSegment.java:58)
at com.hankcs.hanlp.seg.CRF.CRFSegment.<init>(CRFSegment.java:73)
at test.Main.main(Main.java:56)
是由于CRF比较耗内存,因此出现内存不足,因此须要修改一下VM的最大内存。
选中工程,而后:
便可解决。
在源码包文件在eclipse中打开出现乱码,解决方法:
(必须)首先用txt打开,而后在第一行添加:encoding="utf-8"便可。
转载自CrazyNong 的博客