NLP - Standord NLP


关于 Standord NLP

https://stanfordnlp.github.io


优点

  • 一个集成的语言分析工具集;
  • 进行快速,可靠的任意文本分析;
  • 整体的高质量的文本分析(分词拿过全球第一名);
  • 支持多种主流语言(支持中文);
  • 多种编程语言的易用接口(可以使用 python 或 java 调用);
  • 方便的简单的部署web服务。
  • 功能强大
    • 能给出基本的词形、词性识别
    • 解析句子结构、自此以来
    • 词性分类
    • 关系抽取、信息抽取

安装

1、安装 jdk
Standord NLP 是 Java 语言开发的,所以需要安装 JDK


2、安装 stanfordnlp、stanfordcorenlp

$ pip install stanfordnlp

$ pip install stanfordcorenlp	

3、下载 CoreNLP 及模型 jar 包
两者都在这个地址:https://stanfordnlp.github.io/CoreNLP/

下载 CoreNLP
在这里插入图片描述


下载 Chinese 对应的 jar 包
约 1.3G,下载时间较长
我下载的jar包文件名为:stanford-corenlp-4.2.0-models-chinese.jar
在这里插入图片描述


将上述下载的两个内容,解压后放在同一个文件夹下,这里为这个文件夹取名为 stanfordnlp ,在我电脑的地址上为 /Users/xx/Downloads/Safari/stanfordnlp


调用测试

from stanfordcorenlp import StanfordCoreNLP	
nlp = StanfordCoreNLP('/Users/xx/Downloads/Safari/stanfordnlp', lang='zh')	

可能会报如下错误:
问题1:stanford-chinese-corenlp-yyyy-MM-dd-models.jar not exists

OSError: stanford-chinese-corenlp-yyyy-MM-dd-models.jar not exists. You should download and place it in the /Users/xx/Downloads/Safari/stanfordnlp/ first.

将 jar 包文件名从 stanford-corenlp-4.2.0-models-chinese.jar 改为


问题2:psutil.AccessDenied (pid=19000)
pid 后数字不同,仅代表跑这个程序的进程,而非权限控制相关进程。

相关信息

On macOS this function requires root privileges.

答案一般围绕使用 root 权限来执行文件,但 jupyter 我不确定如何使用root权限。

尝试使用 sudo jupyter notebook 来重启 notebook,启动失败,提示:不建议以root身份运行.使用--allow-root绕过过.


(base) $ jupyter notebook --allow-root

如上重启 notebook,再次运行代码。依然失败,放弃 jupyter。


使用pycharm 创建 .py 文件写入上述代码,

执行:

(base) $ python sf01.py 
Traceback (most recent call last):
  File "/Users/xx/opt/anaconda3/lib/python3.7/site-packages/psutil/_psosx.py", line 339, in wrapper
    return fun(self, *args, **kwargs)
  File "/Users/xx/opt/anaconda3/lib/python3.7/site-packages/psutil/_psosx.py", line 528, in connections
    rawlist = cext.proc_connections(self.pid, families, types)
PermissionError: [Errno 1] Operation not permitted

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "sf01.py", line 2, in <module>
    nlp = StanfordCoreNLP('stanfordnlp', lang='zh')
  File "/Users/xx/opt/anaconda3/lib/python3.7/site-packages/stanfordcorenlp/corenlp.py", line 79, in __init__
    if port_candidate not in [conn.laddr[1] for conn in psutil.net_connections()]:
  File "/Users/xx/opt/anaconda3/lib/python3.7/site-packages/psutil/__init__.py", line 2263, in net_connections
    return _psplatform.net_connections(kind)
  File "/Users/xx/opt/anaconda3/lib/python3.7/site-packages/psutil/_psosx.py", line 252, in net_connections
    cons = Process(pid).connections(kind)
  File "/Users/xx/opt/anaconda3/lib/python3.7/site-packages/psutil/_psosx.py", line 344, in wrapper
    raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=19105)

添加 sudo 来执行

(base) $ sudo  python sf01.py 
Password:
<stanfordcorenlp.corenlp.StanfordCoreNLP object at 0x7fb20e7c3250>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值