linux系统安装xlrd,Stanford CoreNLP在linux系统中安装与使用

大部分内容来源于:https://github.com/Yuzhen-Li/yuzhenli.github.io/wiki/Stanford-CoreNLP%E5%9C%A8Ubuntu%E4%B8%8B%E7%9A%84%E5%AE%89%E8%A3%85%E4%B8%8E%E4%BD%BF%E7%94%A8

1,  安装java运行环境

sudo apt-get install default-jre

sudo apt-get install default-jdk

2,  下载stanford corenlp包

wget http://nlp.stanford.edu/software/stanford-corenlp-full-2018-02-27.zipunzip stanford-corenlp-full-2018-02-27.zip

cd stanford-corenlp-full-2018-02-27/

3,  配置环境变量

for file in `find . -name "*.jar"`; do export CLASSPATH="$CLASSPATH:`realpath $file`"; done

4,  安装

sudo pip3 install stanfordcorenlp

5,  下载中文支持

wget http://nlp.stanford.edu/software/stanford-chinese-corenlp-2018-02-27-models.jar

6,使用方法

fromstanfordcorenlp import StanfordCoreNLP

nlp= StanfordCoreNLP(r'/mnt/f/CMBNLP/stanford-corenlp-full-2018-02-27/', lang='zh') ## 这里是coreNLP的路径,英文去掉 lang='zh'

使用方法1:wrapper

sentence = '中国科学院大学位于北京。'print(nlp.word_tokenize(sentence))

print(nlp.pos_tag(sentence))

print(nlp.ner(sentence))

print(nlp.parse(sentence))

print(nlp.dependency_parse(sentence))

text = 'UCAS is located in Beijing.'# 据目前所知openie功能不支持中文处理output= nlp.annotate(text, properties={'annotators': 'tokenize, ssplit, pos, depparse, natlog, openie','outputFormat': 'json',

"openie.triple.strict":"true",

"openie.max_entailments_per_clause":"1"})

output = json.loads(output)

使用方法2:启用服务器,据说会快一些

from stanfordcorenlp import StanfordCoreNLP

nlp = StanfordCoreNLP('http://localhost', port=9000) # 样例源自https://blog.csdn.net/Hallywood/article/details/80154146

sentence = "Kosgi Santosh sent an email to Stanford University. He didn't get a reply"

print('Tokenize:', nlp.coref(sentence))

nlp.close()

使用方法3:命令调用

import subprocess     ## 来源同上样例

subprocess.call(['java','-cp','F:/Program Files/jars/stanford-corenlp-full-2018-02-27/*','-Xmx4g',

'edu.stanford.nlp.pipeline.StanfordCoreNLP',"-annotators",

"tokenize,ssplit,pos,lemma,ner",'-file','subprocesstest.txt'])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值