from nltk.corpus import wordnet as wn
from graphviz import Digraph
word="genius"
digraph=Digraph("WordNet Graph")
digraph.node(name="root_node",label=word,color="orange",style="filled",fontcolor="white",fontsize="50")
sense_node_id=0
hyponym_node_id=0
hypernym_node_id=0
for sense in wn.synsets(word):
#词义
sense_definition="\n".join(sense.definition().split(" "))
sense_lemma_names=sense.lemma_names()
sense_label="\n".join(sense_lemma_names)
sense_node_name="sense_node_"+str(sense_node_id)
digraph.node(name=sense_node_name,label=sense_label,style="filled",color="#008080",fontcolor="white",fontsize="25")
digraph.edge("root_node",sense_node_name,label=sense_definition,color="#008080&#
python 使用 graphviz 可视化 WordNet
最新推荐文章于 2024-01-06 14:32:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)