HanLP pyhanlp 自定义分词词典

词典格式:

word<tab>pos_tag\n

pyhanlp安装和模型数据路径

使用pyhanlp,具体方法如下:

pip install pyhanlp  # 安装pyhanlp

进入python安装包路径,如

/opt/anaconda3/lib/python3.7/site-packages/pyhanlp/static/

备份和添加新词典

将http://hanlp.properties.in改名为备份文件。
mv hanlp.properties.in hanlp.properties.in.bak

修改hanlp.properties
vim hanlp.properties

向CustomDictionaryPath添加你自定义的词典路径,如:

CustomDictionaryPath=data/dictionary/custom/self_define_dict.txt; 现代汉语补充词库.txt; 全国地名大全.txt; 人名词典.txt; 机构名词典.txt; 上海地名.txt ns; data/dictionary/person/nrf.txt nrf;

保存。

测试添加新词典后的分词效果

python脚本,调用pyhanlp示例:

from pyhanlp import *

print(HanLP.segment("在你想要放弃的时候,想想是什么让你当初坚持走到了这里。总是有人要赢的,那为什么不能是我"))

运行脚本后,系统会检查配置文件hanlp.properties,读取词库的路径,对于自定义词典,第一次会重新生成二进制文件(以后直接用)。


不知为何我的centos6.9安装glibc 2.14后乱码了,unset LD_LIBRARY_PATH就好了。
还有怎么同时正确安装glibc 2.14 glibc 2.16页不知道

posted on 2020-02-22 16:32  likeatree  阅读(1335)  评论(0编辑  收藏  举报

导航