斯坦福python中文分词stanza
1 下载 Stanford CoreNLP相关文件
下载完整的组件 https://stanfordnlp.github.io/CoreNLP/index.html
解压stanford-corenlp-full-2018-02-27.zip,并将下载的模型文件stanford-chinese-corenlp-2018-10-05-models.jar、 StanfordCoreNLP-chinese.properties 拷贝到上述解压的文件夹内
2 配置并检验JAVA环境
java -version
3 下载并安装 stanza
stanza源文件 https://codeload.github.com/stanfordnlp/stanza/zip/master
在解压的文件内执行 python3 setup.py install
4 启动服务
java -Xmx6g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties StanfordCoreNLP-chinese.properties -port 9000 -timeout 15000
5 通过python调用分词验证
from stanza.nlp.corenlp import CoreNLPClient
client = CoreNLPClient(server=' http://localhost:9000', default_annotators=['ssplit', 'lemma', 'tokenize
', 'pos', 'ner']) # 注意在以前的版本中,中文分词为 segment,新版已经和其他语言统一为 tokenize
# 分词和词性标注测试
test1 = "财政部会计司发布通知称,上海财经大学会计学院原副教授钱逢胜同志不再符合担任企业会计准则咨询委员
会委员条件,现决定辞聘钱逢胜担任的企业会计准则咨询委员会委员。"
annotated = client.annotate(test1)
for sentence in annotated.sentences:
for token in sentence:
print(token)