本文共 2005 字,大约阅读时间需要 6 分钟。
1 环境准备centos7,可通公网,已配置jdk1.8,已安装python3
2 pip安装pylanlp包
pip3 install pyhanlp
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting pyhanlp
Collecting jpype1==0.7.0 (from pyhanlp)
Downloading http://pypi.doubanio.com/packages/28/63/784834e8a24ec2e1ad7f703c3dc6c6fb372a77cc68a2fdff916e18a4449e/JPype1-0.7.0.tar.gz (470kB)
100% |████████████████████████████████| 471kB 1.1MB/s
Building wheels for collected packages: jpype1
Running setup.py bdist_wheel for jpype1 ... done
Stored in directory: /root/.cache/pip/wheels/39/d1/18/7b45734b5bfed456b96f7f616a884228605c96d06a2efd59d2
Successfully built jpype1
Installing collected packages: jpype1, pyhanlp
Successfully installed jpype1-0.7.0 pyhanlp-0.1.66
3 下载模型及数据(本人由于网速太慢取消下载,使用迅雷下载文件存放至指定目录,再运行hanlp即可)
[root@localhost ~]# hanlp
下载 https://file.hankcs.com/hanlp/hanlp-1.7.8-release.zip 到 /usr/local/lib/python3.6/site-packages/pyhanlp/static/hanlp-1.7.8-release.zip
100.00%, 1 MB, 232 KB/s, 还有 0 分 0 秒
下载 https://file.hankcs.com/hanlp/data-for-1.7.5.zip 到 /usr/local/lib/python3.6/site-packages/pyhanlp/static/data-for-1.7.8.zip
4 分词测试:
交互分词-[root@localhost static]# hanlp segment
喜欢她
喜欢/vi 她/rr
飞流直下三千尺,疑是银河落九天
飞流直下三千尺/vl ,/w 疑/vg 是/vshi 银河/ns 落九天/i
重定向分词-[root@localhost static]# hanlp segment <<< '智能运维怎么做'
智能/n 运维/nz 怎么做/nz
不标注词性-[root@localhost static]# hanlp segment --no-tag <<< '天涯明月刀'
天涯 明月 刀
[root@localhost static]# vim baidu.txt
文本分词-[root@localhost static]# hanlp segment --no-tag < baidu.txt > cut_baidu.txt -a crf --notag
usage: hanlp [-h] [-v] {segment,parse,serve,update} ...
hanlp: error: unrecognized arguments: --notag
[root@localhost static]# hanlp segment --no-tag < baidu.txt > cut_baidu.txt -a crf --no-tag
[root@localhost static]# cat cut_baidu.txt
一个 人 经过 不同 程度 的 锻炼 , 就 获得 不同 程度 的 修养 、 不同 程度 的 效益 。 好 比 香料 , 捣 得 愈碎 , 磨 得愈 细 , 香 得愈 浓烈 。 我们 曾 如此 渴望 命运 的 波澜 , 到 最后 才 发现 : 人生 最 曼妙 的 风景 , 竟是 内心 的 淡定 与 从容 …… 我们 曾 如此 期盼 外界 的 认可 , 到 最后 才 知道 : 世界 是 自己 的 , 与 他人 毫无关系 。
转载地址:https://blog.csdn.net/qq_29590285/article/details/107350353 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!