from c541 import Morph, Chunk, return_chunk for sentence in return_chunk(): for num in range(len(sentence)): #名詞を含む文節の時 if "名詞" not in [morph.pos for morph in sentence[num].morphs]: continue print("".join([ morph.surface if morph.pos != "記号" else "" for morph in sentence[num].morphs ]), end=" ") next_chunk = sentence[num].dst while next_chunk != -1: print("->", "".join([ morph.surface if morph.pos != "記号" else "" for morph in sentence[next_chunk].morphs ]), end=" ") next_chunk = sentence[next_chunk].dst print("")
from c541 import Morph, Chunk, return_chunk from graphviz import Digraph G = Digraph(format='png') G.attr('node', shape='circle') sentence = return_chunk()[2] for num in range(len(sentence)): #ノードの追加 node_name = "".join([ morph.surface if morph.pos != "記号" else "" for morph in sentence[num].morphs ]) G.node(str(num), node_name) for num in range(len(sentence)): if sentence[num].dst != -1: modifier = num modifiee = sentence[num].dst G.edge(str(modifier), str(modifiee)) G.render("tree")