pyhanlp window安装以及人名提取例子

window pyhanlp安装

pyhanlp目前使用jpype1这个Python包来调用HanLP
所以需要安装jpype1,到https://www.lfd.uci.edu/~gohlke/pythonlibs/下载对应python版本的whl。

  1. 安装pip install JPype1-0.7.1-cp36-cp36m-win_amd64.whl
  2. 再安装pip install pyhanlp -i https://pypi.douban.com/simple

ValueError: 配置错误: 数据包 D:/DevFiles/Anaconda3/lib/site-packages/pyhanlp/static\data 不存在,请修改配置文件中的root
到https://github.com/hankcs/HanLP/releases在页面中下载data-for-1.7.5.zip

然后把下载的文件放到/XXX/lib/site-packages/pyhanlp/static\ 目录下(放在你自己的pyhanlp包下边)
解压文件,如下图
在这里插入图片描述

人名提取例子

    from pyhanlp import *

    document = "对一些超过红线的地方,陈明忠和周毅表示,对一些取用水项目进行区域的限批,严格地进行水资源论证和取水许可的批准。"
    segment = HanLP.newSegment().enableNameRecognize(True)
    term_list = segment.seg(document)
    for term in term_list:
        if re.search(r'/nr', str(term)):
            print(str(term))

返回结果
陈明忠/nr
周毅/nr

猜你喜欢

转载自blog.csdn.net/qq_33873431/article/details/103678407