Exemple #1
0
    def unary_add_child_for_constituentnode(self,
                                            old_node: ConstituentNode,
                                            add_left=True):
        """

        :param old_node:
        :param add_left:
        :return:
        """
        label = self.next_free_label()
        new_node = self.create_node(label=label, relative=old_node)
        children = old_node.get_children(similar=True, visible=False)

        if len(children) != 1:
            return
        child = children[0]
        old_edge = old_node.get_edge_to(child)
        if add_left:
            self.connect_node(parent=old_node,
                              child=new_node,
                              direction=g.LEFT,
                              fade_in=True)
        else:
            self.connect_node(parent=old_node,
                              child=new_node,
                              direction=g.RIGHT,
                              fade_in=True)
Exemple #2
0
    def unary_add_child_for_constituentnode(self, old_node: ConstituentNode, add_left=True):
        """

        :param old_node:
        :param add_left:
        :return:
        """
        new_node = self.create_node(relative=old_node)
        children = old_node.get_children(similar=True, visible=False)

        if len(children) != 1:
            return
        child = children[0]
        old_edge = old_node.get_edge_to(child)
        if add_left:
            self.connect_node(parent=old_node, child=new_node, direction=g.LEFT, fade_in=True)
        else:
            self.connect_node(parent=old_node, child=new_node, direction=g.RIGHT, fade_in=True)
Exemple #3
0
    def add_sibling_for_constituentnode(self,
                                        old_node: ConstituentNode,
                                        add_left=True):
        """ Create a new merger node to top of this node and have this node and new node as its
        children.
        :param old_node:
        :param add_left: adding node to left or right -- if binary nodes, this marks which one
        will be projecting.
        :return:
        """

        new_node = self.create_node(label=self.next_free_label(),
                                    relative=old_node)
        new_node.heads = [new_node]

        if add_left:
            left = new_node
            right = old_node
        else:
            left = old_node
            right = new_node
        parent_info = [
            (e.start, e.direction())
            for e in old_node.get_edges_up(similar=True, visible=False)
        ]

        for op, align in parent_info:
            self.disconnect_node(parent=op, child=old_node)

        merger_node = self.create_merger_node(left=left,
                                              right=right,
                                              new=new_node)

        for group in self.groups.values():
            if old_node in group:
                group.add_node(merger_node)

        for op, align in parent_info:
            self.connect_node(parent=op,
                              child=merger_node,
                              direction=align,
                              fade_in=True)
        merger_node.copy_position(old_node)
        merger_node.heads = list(old_node.heads)
Exemple #4
0
    def add_sibling_for_constituentnode(self, old_node: ConstituentNode, add_left=True):
        """ Create a new merger node to top of this node and have this node and new node as its
        children.
        :param old_node:
        :param add_left: adding node to left or right -- if binary nodes, this marks which one
        will be projecting.
        :return:
        """

        new_node = self.create_node(relative=old_node)

        if add_left:
            left = new_node
            right = old_node
        else:
            left = old_node
            right = new_node
        parent_info = [(e.start, e.direction(), e.start.heads) for e in
                       old_node.get_edges_up(similar=True, visible=False)]

        for op, align, head in parent_info:
            self.disconnect_node(parent=op, child=old_node)

        merger_node = self.create_merger_node(left=left, right=right, new=new_node)

        # Fix trees to include new node and especially the new merger node
        for tree in set(old_node.trees):
            tree.recalculate_top()
            tree.update_items()

        for group in self.groups.values():
            if old_node in group:
                group.add_node(merger_node)

        for op, align, head in parent_info:
            self.connect_node(parent=op, child=merger_node, direction=align, fade_in=True)
        merger_node.copy_position(old_node)
        merger_node.heads = [old_node]
        for op, align, head_nodes in parent_info:
            if old_node in head_nodes:
                op.heads = list(head_nodes)  # fixme: not sure if we treat multiple heads right