一、环境配置
1.下载官网的NLP相关包
将下载下来的stanford-corenlp-full-2018-02-27解压并将下载英文的jar文件
stanford-english-corenlp-2018-02-27-models.jar放到该目录下。
网址:https://stanfordnlp.github.io/CoreNLP/index.html
2.确保电脑里要已经安装java环境
3.在Python中安装stanfordcorenlp
使用pip安装stanfordcorenlp:
pip install stanfordcorenlp
二、在Python环境下调用stanfordcorenlp
from stanfordcorenlp import StanfordCoreNLP
import nltk
from nltk.tree import Tree as nltkTree
##读取stanford-corenlp所在的目录
nlp = StanfordCoreNLP(r'F:\stanford-corenlp-full-2018-02-27')
#输入句子
sentence = 'Video becomes a new way of communication between Internet users with the proliferation of sensor-rich mobile devices.'
print('Part of Speech:', nlp.pos_tag(sentence))
标注结果:
三、查看词性标注
在浏览器中访问:http://localhost:9000/
四、中文NLP句子分析
将下载下来的stanford-corenlp-full-2018-02-27解压并将下载英文的jar文件
stanford-chinese-corenlp-2018-02-27-models.jar放到该目录下。
from stanfordcorenlp import StanfordCoreNLP
import nltk
from nltk.tree import Tree as nltkTree
nlp = S