Stanford CoreNLP 提取句子名词

一、环境配置

Stanford CoreNLP 工具包的使用

我的另一篇博客:https://zhuanlan.zhihu.com/p/44180488

二、实例

1.导入已经下载的工具包

from stanfordcorenlp import StanfordCoreNLP
import nltk
from nltk.tree import Tree as nltkTree

nlp = StanfordCoreNLP('./StanfordNLP工具包/stanford-corenlp-full-2018-02-27') 

2.句子的词性标注

sentence = 'person removes plate out of cabinet' #输入句子

sen_tag = nlp.pos_tag(sentence)  #词性标注
print(sen_tag)

结果:

NN 为名词,保留标注为‘NN’ 的单词到列表中。

noun_word = []
for i in range(len(sen_tag)):
    if sen_tag[i][1] == 'NN':
        noun_word.append(sen_tag[i][0])
print(noun_word)

结果:

猜你喜欢

转载自blog.csdn.net/qq_33373858/article/details/83793573