环境:Windows、python3.6
1、下载包:官网网址:https://github.com/hankcs/HanLP,亲测利用方法二可行
2、安装python的pyhanlp包:pip install pyhanlp
3、Windows用户如果遇到:
- building '_jpype' extension
- error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual
- C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
可以按提示安装Visual C++,也可以安装轻量级的Miniconda(推荐,超方便):
4、若已安装anaconda,则直接运行下面代码:
conda install -c conda-forge jpype1
pip install pyhanlp
5、运行下面情况,则说明安装pyhanlp成功
6、运行下面代码将可视化存储:
from jpype import *
startJVM(getDefaultJVMPath(), "-Djava.class.path=E:\hanlp\hanlp-1.5.4.jar;E:\hanlp", "-Xms1g", "-Xmx1g")
HanLP = JClass('com.hankcs.hanlp.HanLP')
print(HanLP.parseDependency("徐先生还具体帮助他确定了把画雄鹰、松鼠和麻雀作为主攻目标。"))#该行可删除
f = open("E:/ab.txt",'w', encoding='utf-8')
print((HanLP.parseDependency("徐先生还具体帮助他确定了把画雄鹰、松鼠和麻雀作为主攻目标。")),file = f)
f.close()
7、下载可视化工具DependencyViewer:
http://nlp.nju.edu.cn/tanggc/tools/DependencyViewer.exe
8、利用dependencyViewer打开写入的txt文件e:/ab.txt即可。