Esempio n. 1
0
    def add_branch(self, node=None, text=None):
        """Add new node to specified existing node.

           Input Arguments:
               node - ID of node to branch off.  Default is START_OF_BOOK
               text - Text to associate with newly created node.  Default is ""

           Returns:
               ID of newly created node

        """
        node = node or self._BEGIN
        assert(node in self._nodes)
        new_node = Node()
        new_id   = new_node.get_id()
        if text is not None:
            new_node.set_text(text)
        self._nodes[new_id] = new_node
        self._nodes[node].add_link(new_id)
        return new_id
Esempio n. 2
0
    def add_branch(self, node=None, text=None):
        """Add new node to specified existing node.

           Input Arguments:
               node - ID of node to branch off.  Default is START_OF_BOOK
               text - Text to associate with newly created node.  Default is ""

           Returns:
               ID of newly created node

        """
        node = node or self._BEGIN
        assert (node in self._nodes)
        new_node = Node()
        new_id = new_node.get_id()
        if text is not None:
            new_node.set_text(text)
        self._nodes[new_id] = new_node
        self._nodes[node].add_link(new_id)
        return new_id
Esempio n. 3
0
    def insert_branch(self, node, break_pt):
        """Break a specified node in two, thus introducing a new branch point.

           Input Arguments:
               node     - ID of node to insert branch point
               break_pt - location in node for new branch point

           Returns:
               ID of original node

        """
        assert(node in self._nodes)
        assert(0 < break_pt < len(self._nodes[node].get_text()))
        new_node = Node()
        new_id   = new_node.get_id()
        new_node.set_text(self._nodes[node].get_text()[break_pt:])
        new_node._set_links(self._nodes[node].get_links())
        self._nodes[new_id] = new_node
        self._nodes[node].set_text(self._nodes[node].get_text()[0:break_pt])
        self._nodes[node]._set_links({new_id: 0.0})
        return node
Esempio n. 4
0
    def insert_branch(self, node, break_pt):
        """Break a specified node in two, thus introducing a new branch point.

           Input Arguments:
               node     - ID of node to insert branch point
               break_pt - location in node for new branch point

           Returns:
               ID of original node

        """
        assert (node in self._nodes)
        assert (0 < break_pt < len(self._nodes[node].get_text()))
        new_node = Node()
        new_id = new_node.get_id()
        new_node.set_text(self._nodes[node].get_text()[break_pt:])
        new_node._set_links(self._nodes[node].get_links())
        self._nodes[new_id] = new_node
        self._nodes[node].set_text(self._nodes[node].get_text()[0:break_pt])
        self._nodes[node]._set_links({new_id: 0.0})
        return node