问题描述
代码:
from stanfordcorenlp import StanfordCoreNLP
import logging
#中文中的应用,一定记得下载中文jar包,并标志lang=‘zh’
nlp_zh = StanfordCoreNLP(r'D:\stanford-corenlp-full-2016-10-31', port=8094, lang='zh',quiet=False,logging_level=logging.DEBUG)
sentence_zh = '清华大学位于北京。'
print(nlp_zh.word_tokenize(sentence_zh))
print(nlp_zh.pos_tag(sentence_zh))
print(nlp_zh.ner(sentence_zh))
print(nlp_zh.parse(sentence_zh))
print(nlp_zh.dependency_parse(sentence_zh))
用到的依赖包:stanford-corenlp-full-2016-10-31、stanford-chinese-corenlp-2016-10-31-models.jar
结果:
['', '', '', '', '']
[('', 'NR'), ('', 'NN'), ('', 'VV'), ('', 'NR'), ('', 'PU')]
[('', 'ORGANIZATION'), ('', 'ORGANIZATION'), ('', 'O'), ('', 'GPE'), ('', 'O')]
(ROOT
(IP
(NP (NR 清华) (NN 大学))
(VP (VV 位于)
(NP (NR 北京)))
(PU 。