声明:转载请注明出处,谢谢:https://www.jianshu.com/p/0faddfe6cbad
另外,更多实时更新的个人学习笔记分享,请关注:
知乎:https://www.zhihu.com/people/yuquanle/columns
公众号:StudyForAI
CSDN地址:http://blog.csdn.net/m0_37306360
Stanford CoreNLP句子成分分析(constituency parse)
安装:pip install stanfordcorenlp
国内源安装:pip install stanfordcorenlp -i https://pypi.tuna.tsinghua.edu.cn/simple
from stanfordcorenlp import StanfordCoreNLP
使用stanfordcorenlp进行句法成分分析
先下载模型,下载地址:https://nlp.stanford.edu/software/corenlp-backup-download.html
对中文进行句子成分分析
zh_model = StanfordCoreNLP(r'stanford-corenlp-full-2018-02-27', lang='zh')
s_zh = '我爱自然语言处理技术!'
con_zh = zh_model.parse(s_zh)
print(con_zh)
(ROOT
(IP
(IP
(NP (NN 我爱))
(ADVP (AD 自然))
(NP (NN 语言))
(VP (VV 处理)
(NP (NN 技术))))
(PU !)))
对英文进行句子成分分析
eng_model = StanfordCoreNLP(r'stanford-corenlp-full-2018-02-27')
s_eng = 'I love natural language processing technology!'
con_eng = eng_model.parse(s_eng)
print(con_eng)
(ROOT
(S
(NP (PRP I))
(VP (VBP love)
(NP (JJ natural) (NN language) (NN processing) (NN technology)))
(. !)))