Stanford CoreNLP安装及使用

安装:

1.下载

网址: Overview - CoreNLP 

处理中文还需要下载中文的模型jar文件,然后放到stanford-corenlp-full-2018-02-27根目录下即可

2.准备jar包

将下载下来的stanford-corenlp-full-2016-10-31解压并将下载中文的jar文件
stanford-chinese-corenlp-2016-10-31-models.jar放到该目录下。

3.安装

安装Stanford CoreNLP工具

!pip install stanfordcorenlp

使用

1.代码引入

from stanfordcorenlp import StanfordCoreNLP

nlp= StanfordCoreNLP(r'D:\Soft\tool\stanford-corenlp-4.5.7', lang='zh')
sentence = '浙江大学有七个校区。'
print(nlp.word_tokenize(sentence))
print(nlp.pos_tag(sentence))
print(nlp.ner(sentence))
print(nlp.parse(sentence))
print(nlp.dependency_parse(sentence))
nlp.close()

(1)导入

nlp = StanfordCoreNLP(r’D:\Soft\tool\stanford-corenlp-4.5.7’)

nlp= StanfordCoreNLP(r'D:\Soft\tool\stanford-corenlp-4.5.7', lang='zh')

读入的地址是文件夹地址,不指定语言的话默认是英语。

(2)分词 Tokenization

nlp.word_tokenize

(3)词性标注 Part-of-speech Tagging

nlp.pos_tag(sentence)

(4)实体识别 NERCombinerAnnotator

nlp.ner(sentence)

(5)句法成分分析 Constituency Parsing

nlp.parse(sentence)

(5)依存句法分析

nlp.dependency_parse(sentence)

更多用法见Full List Of Annotators - CoreNLP

2.命令行开启服务器

命令行输入,开启 CoreNLP服务器

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 7000 -timeout 15000

程序内调用

# Use an existing server
nlp = StanfordCoreNLP('http://localhost', port=7000)

在浏览器访问http://localhost:7000/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值