安装并开始使用stanford corenlp
方法一
有两种方式,一种是直接使用已经包装好的python wrapper,见网址 https://pypi.org/project/corenlp-client/,或者https://stanfordnlp.github.io/stanfordnlp/corenlp_client.html用Python开发的CoreNLP客户端工具。下载必要的软件包和相应的模型,就可以使用corenlp客户端启动corenlp服务器。
import corenlp
#tokenize pos lemma 可以选择其他的 这里就不多写了
client = corenlp.CoreNLPClient(annotators="tokenize pos lemma".split())
ann = client.annotate(sent)
缺点
不能并行,会出现以下错误
Cannot assign requested address
因为只适用于简单的测试,当数据很多,需要并行时,建议使用以下方法
方法二
直接安装(先看完后面,先别安装,这是一个排坑过程!!!!)
pip install stanfordcorenlp
github地址
点击下面地址
https://stanfordnlp.github.io/CoreNLP/index.html#download
下载之后解压缩。
下载相应语言模型并放在上面解压缩的包里。
from stanfordcorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP(r'./stanford-corenlp-full-2018-10-05',lang='en'