python实现中文依存句法分析

需求:python实现中文依存句法分析

(最初尝试了NLTK库来实现,发现只能实现英文,不能应用中文场景)

方法一、斯坦福依存句法分析处理中文

斯坦福依存句法分析参考教程地址:https://blog.csdn.net/guolindonggld/article/details/72795022

安装stanfordcorenlp包之前: 
1:下载安装JDK 1.8及以上版本。 
2:下载Stanford CoreNLP文件,解压。 

3:处理中文还需要下载中文的模型jar文件,然后放到stanford-corenlp-full-2016-10-31根目录下即可(注意一定要下载这个文件哦,否则它默认是按英文来处理的)。

4.install  stanfordcorenlp


#encoding=utf-8

from stanfordcorenlp import StanfordCoreNLP

nlp = StanfordCoreNLP(r'./stanford-corenlp-full-2016-10-31/', lang='zh')    #英文使用 lang='en'

sentence = "清华大学位于北京。"
# sentence = "The book is very interesting."

# print nlp.word_tokenize(sentence)
# print nlp.pos_tag(sentence)
print nlp.parse(sentence)
print nlp.dependency_parse(sentence)

结果如下:

(ROOT
  (IP
    (NP (NR 清华) (NN 大学))
    (VP (VV 位于)
      (NP (NR 北京)))
    (PU 。)))
[(u'ROOT', 0, 3), (u'compound:nn', 2, 1), (u'nsubj', 3, 2), (u'dobj', 3, 4), (u'punct', 3, 5)]
方法二、哈工大LTP处理中文(有时间再补充具体实现)


你可能感兴趣的:(python实现中文依存句法分析)