command.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:tetre 作者: aoldoni 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号