zoukankan      html  css  js  c++  java
  • 学习笔记(35)-安装pyhanlp

    安装pyhanlp

    pyhanlp是java写的,外层封装了python。

    对于新手,在使用的时候稍有难度。

    1. 下载源码

    https://github.com/hankcs/pyhanlp

    git clone https://github.com/hankcs/pyhanlp.git
    

    2. 创建虚机

    python3 -m venv env
    source env/bin/activate
    

    3. 安装pyhanlp

    cd pyhanlp
    pip install -e .
    

    以下是日志

    Obtaining file:///Users/huihui/git/pyhanlp
    Collecting jpype1==0.7.0 (from pyhanlp==0.1.62)
      Using cached https://files.pythonhosted.org/packages/28/63/784834e8a24ec2e1ad7f703c3dc6c6fb372a77cc68a2fdff916e18a4449e/JPype1-0.7.0.tar.gz
    Installing collected packages: jpype1, pyhanlp
      Running setup.py install for jpype1 ... done
      Running setup.py develop for pyhanlp
    Successfully installed jpype1-0.7.0 pyhanlp
    You are using pip version 19.0.3, however version 20.0.2 is available.
    You should consider upgrading via the 'pip install --upgrade pip' command.
    
    

    尝试调用,加载词典

    (env) huihui@192 pyhanlp % python
    
    Python 3.7.3 (default, Nov 15 2019, 04:04:52) 
    [Clang 11.0.0 (clang-1100.0.33.16)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pyhanlp
    下载 http://hanlp.com/static/release/hanlp-1.7.6-release.zip 到 /Users/huihui/git/pyhanlp/pyhanlp/static/hanlp-1.7.6-release.zip
    100.00%, 1 MB, 514 KB/s, 还有 0 分  0 秒   
    下载 https://file.hankcs.com/hanlp/data-for-1.7.zip 到 /Users/huihui/git/pyhanlp/pyhanlp/static/data-for-1.7.6.zip
    0.38%, 2 MB, 795 KB/s, 还有 13 分 37 秒   下载失败 https://file.hankcs.com/hanlp/data-for-1.7.zip 由于 timeout('The read operation timed out')
    请参考 https://github.com/hankcs/pyhanlp 执行手动安装.
    或手动下载 https://file.hankcs.com/hanlp/data-for-1.7.zip 到 /Users/huihui/git/pyhanlp/pyhanlp/static/data-for-1.7.6.zip
    是否前往 https://github.com/hankcs/pyhanlp ?(y/n)y
    (env) huihui@192 pyhanlp % 
    

    4. 下载词典文件

    手动下载。

    词典文件有668M,下载之后按照上述提示放置目录,并解压。

    5.测试pyhanlp

    测试例子1,在命令行

    (env) huihui@192 pyhanlp % python
    Python 3.7.3 (default, Nov 15 2019, 04:04:52) 
    [Clang 11.0.0 (clang-1100.0.33.16)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from pyhanlp import *
    >>> 
    >>> print(HanLP.segment('出事了电脑'))
    [出事/vi, 了/ule, 电脑/n]
    >>> 
    

    测试例子2,在PyCharm

    选择刚才创建的虚机

    from pyhanlp import *
    
    print(HanLP.segment('你好,欢迎在Python中调用HanLP的API'))
    for term in HanLP.segment('下雨天地面积水'):
        print('{}	{}'.format(term.word, term.nature)) # 获取单词与词性
    
    print(HanLP.segment('你好,欢迎在Python中调用HanLP的API'))
    
    
  • 相关阅读:
    Device eth0 does not seem to be present, delaying initialization(解决克隆CentOS6.3虚拟机后网卡设备无法启动问题)
    CI整合Smarty
    修改crontab默认的编辑器
    添加数据之后不跳页面显示一个漂亮的提示信息(非ajax提交数据)
    jsp连接mysql数据库
    PHP使用CURL详解
    内、外部号码范围配置
    更改SAP的字段翻译
    SAP 应用服务负载均衡的实现
    SAP中禁止特定用户更改密码
  • 原文地址:https://www.cnblogs.com/xuehuiping/p/12323080.html
Copyright © 2011-2022 走看看