自然语言处理之:搭建基于HanLP的开发环境
4617 点击·0 回帖
![]() | ![]() | |
![]() | 环境搭建比FNLP的简单,具体参考:https://github.com/hankcs/hanlp
各个版本的下载:https://github.com/hankcs/HanLP/releases 完毕后有一个报错: 字符类型对应表加载失败: D:/eclipse_workspace/HanLPTest/HanLP/data/dictionary//other/CharType.dat.yes 直接在 D:/eclipse_workspace/HanLPTest/HanLP/data/dictionary//other/ 目录下新建一个txt文档将名称改为 CharType.dat.yes 即可。 相对比较简单。 尝试HanLP主要处于各个开源自然语言处理工具包之间的差异,寻找一个适合学习的开源工具包。 图片:DKhadoop.jpg ![]() HanLP调用方法 HanLP几乎所有的功能都可以通过工具类HanLP快捷调用,当你想不起来调用方法时,只需键入HanLP.,IDE应当会给出提示,并展示HanLP完善的文档。所有Demo都位于com.hankcs.demo下,比文档覆盖了更多细节,更新更及时,强烈建议运行一遍。 HanLP的适用过程中注意的问题: 1、因为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的最大内存。 选中工程,然后: 图片:图1.png ![]() 即可解决。 在源码包文件在eclipse中打开出现乱码,解决方法: (必须)首先用txt打开,然后在第一行添加:encoding="utf-8"即可。 图片:图2.png ![]() 转载自CrazyNong 的博客 | |
![]() | ![]() |