Hanlp依存句法 可視化

導入pyhanlp包,並調用依存句法分析方法。

具體hanlp的一些常用方法等,可參考另一篇文章 Hanlp安裝使用詳解

from pyhanlp import * 

para_sen = "馬伊琍與文章宣佈離婚,華爲是背後的贏家。"
sentence = HanLP.parseDependency(para_sen)
print(sentence)

# 輸出依存文法的結果 txt文件,在windows系統下的 Dependency Viewer.exe 打開文件
path = "/Users/aaaa/Documents/Work/aa.txt"
with open(path, "w", encoding='utf-8') as f:
     f.write(str(sentence))
print("path:%s" % (path))

輸出結果 

將輸出的txt文件在Dependency Viewer中打開顯示如下:   DependencyViewer.exe下載地址

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章