詞典格式:
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頁不知道