使用

from stanfordcorenlp import StanfordCoreNLP

# 加载模型
nlp = StanfordCoreNLP(r"D:\Data\NLP\model\stanford_corenlp\stanford-corenlp-full-2018-10-05", lang='zh')

# 使用
text = "清华大学是一所中国的一流大学。"

print('Tokenize:', nlp.word_tokenize(text))
print('Part of Speech:', nlp.pos_tag(text))
print('Named Entities:', nlp.ner(text))
print('Constituency Parsing:', nlp.parse(text))
print('Dependency Parsing:', nlp.dependency_parse(text))

参考

报错

按照网上教程下载模型并且运行代码后没反应,然后搜索网上相关解决方案,找到了关于使用stanfordcorenlp一直运行不报错的解决方法 - monty12 - 博客园,并且设置了logger.DEBUG后发现了类似以下报错信息,然后继续重装Java,经过反复两次发现还是不行。

nitializing native server...
INFO:root:java -Xmx4g -cp "F:\space\wingide\stanfordnlp\*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000
INFO:root:Server shell PID: 8504
INFO:root:Waiting until the server is available.
INFO:root:Waiting until the server is available.

后来从这个网址:Java SE Runtime Environment 8 - Downloads,下载了如下红框中标出的链接重新安装Java之后,才提示安装了64位,并且程序可以正常运行。

lUi4iV.png

评论




博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议

本站使用 Volantis 作为主题,总访问量为
载入天数...载入时分秒...
冀ICP备20001334号