def sentence_to_graph_recursive(self, token, parent_id, e):
"""Recursive function on each node as to generates the sentence dependency tree image.
Args:
token: The string token raw text.
parent_id: The id of the parent node this token is a child of in the dependency tree.
e: The graphical object (graphviz.Digraph).
"""
if len(list(token.children)) == 0:
return
current_global_id = {}
for child in token.children:
self.current_token_id += 1
current_global_id[str(self.current_token_id)] = child
for child_id, child in current_global_id.items():
self.sentence_to_graph_add_node(e, child_id, child.orth_)
e.edge(str(parent_id), child_id, label=child.dep_)
for child_id, child in current_global_id.items():
self.sentence_to_graph_recursive(child, child_id, e)
评论列表
文章目录