当前位置: 首页>>代码示例>>Python>>正文


Python Tree.move_node方法代码示例

本文整理汇总了Python中treelib.Tree.move_node方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.move_node方法的具体用法?Python Tree.move_node怎么用?Python Tree.move_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在treelib.Tree的用法示例。


在下文中一共展示了Tree.move_node方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AcquisitionChain

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import move_node [as 别名]
class AcquisitionChain(object):
    def __init__(self):
        self._tree = Tree()
        self._root_node = self._tree.create_node("acquisition chain", "root")
        self._device_to_node = dict()

    def add(self, master, slave):
        slave_node = self._tree.get_node(slave)
        master_node = self._tree.get_node(master)
        if slave_node is not None and isinstance(slave, AcquisitionDevice):
            if slave_node.bpointer is not self._root_node and master_node is not slave_node.bpointer:
                raise RuntimeError(
                    "Cannot add acquisition device %s to multiple masters, current master is %s"
                    % (slave, slave_node._bpointer)
                )
            else:  # user error, multiple add, ignore for now
                return

        if master_node is None:
            master_node = self._tree.create_node(tag=master.name, identifier=master, parent="root")
        if slave_node is None:
            slave_node = self._tree.create_node(tag=slave.name, identifier=slave, parent=master)
        else:
            self._tree.move_node(slave_node, master_node)

    def _execute(self, func_name):
        tasks = list()

        prev_level = None
        for dev in reversed(list(self._tree.expand_tree(mode=Tree.WIDTH))[1:]):
            node = self._tree.get_node(dev)
            level = self._tree.depth(node)
            if prev_level != level:
                gevent.joinall(tasks)
                tasks = list()
            func = getattr(dev, func_name)
            tasks.append(gevent.spawn(func))
        gevent.joinall(tasks)

    def prepare(self, dm, scan_info):
        # self._devices_tree = self._get_devices_tree()
        for master in (x for x in self._tree.expand_tree() if isinstance(x, AcquisitionMaster)):
            del master.slaves[:]
            for dev in self._tree.get_node(master).fpointer:
                master.slaves.append(dev)

        dm_prepare_task = gevent.spawn(dm.prepare, scan_info, self._tree)

        self._execute("_prepare")

        dm_prepare_task.join()

    def start(self):
        self._execute("_start")
        for acq_dev in (x for x in self._tree.expand_tree() if isinstance(x, AcquisitionDevice)):
            acq_dev.wait_reading()
            dispatcher.send("end", acq_dev)
开发者ID:mguijarr,项目名称:bliss,代码行数:59,代码来源:continuous_scan.py

示例2: test_loop

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import move_node [as 别名]
 def test_loop(self):
     tree = Tree()
     tree.create_node('a', 'a')
     tree.create_node('b', 'b', parent='a')
     tree.create_node('c', 'c', parent='b')
     tree.create_node('d', 'd', parent='c')
     try:
         tree.move_node('b', 'd')
     except LoopError:
         pass
开发者ID:caesar0301,项目名称:treelib,代码行数:12,代码来源:test_tree.py

示例3: AcquisitionChain

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import move_node [as 别名]
class AcquisitionChain(object):
    def __init__(self, parallel_prepare=False):
        self._tree = Tree()
        self._root_node = self._tree.create_node("acquisition chain", "root")
        self._device_to_node = dict()
        self._presets_list = list()
        self._parallel_prepare = parallel_prepare
        self._device2one_shot_flag = weakref.WeakKeyDictionary()

    @property
    def nodes_list(self):
        nodes_gen = self._tree.expand_tree()
        nodes_gen.next()  # first node is 'root'
        return list(nodes_gen)

    def add(self, master, slave):
        self._device2one_shot_flag.setdefault(slave, False)

        slave_node = self._tree.get_node(slave)
        master_node = self._tree.get_node(master)
        if slave_node is not None and isinstance(slave, AcquisitionDevice):
            if(slave_node.bpointer is not self._root_node and
               master_node is not slave_node.bpointer):
                raise RuntimeError("Cannot add acquisition device %s to multiple masters, current master is %s" % (
                    slave, slave_node._bpointer))
            else:                 # user error, multiple add, ignore for now
                return

        if master_node is None:
            master_node = self._tree.create_node(
                tag=master.name, identifier=master, parent="root")
        if slave_node is None:
            slave_node = self._tree.create_node(
                tag=slave.name, identifier=slave, parent=master)
        else:
            self._tree.move_node(slave, master)
        slave.parent = master

    def add_preset(self, preset):
        self._presets_list.append(preset)

    def set_stopper(self, device, stop_flag):
        """
        By default any top master device will stop the scan.
        In case of several top master, you can define which one won't
        stop the scan
        """
        self._device2one_shot_flag[device] = not stop_flag

    def __iter__(self):
        if len(self._tree) > 1:
            return AcquisitionChainIter(self, parallel_prepare=self._parallel_prepare)
        else:
            return iter(())
开发者ID:tiagocoutinho,项目名称:bliss,代码行数:56,代码来源:chain.py

示例4: print

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import move_node [as 别名]
    print(tree[child].tag)

print(sep + "OOhh~ new members join Jill's family:")
new_tree = Tree()
new_tree.create_node("n1", 1)  # root node
new_tree.create_node("n2", 2, parent=1)
new_tree.create_node("n3", 3, parent=1)
tree.paste("jill", new_tree)
tree.show()

print(sep + "They leave after a while:")
tree.remove_node(1)
tree.show()

print(sep + "Now Jill moves to live with Grand-x-father Harry:")
tree.move_node("jill", "harry")
tree.show()

print(sep + "A big family for George to send message to the oldest Harry:")
for node in tree.rsearch("george"):
    print(tree[node].tag)
########NEW FILE########
__FILENAME__ = folder_tree
#!/usr/bin/env python
# A file folder scanner contributed by @holger
#
# You can spicify the scanned folder and file pattern by changing rootPath
# and pattern variables
#

__author__ = "holger"
开发者ID:Mondego,项目名称:pyreco,代码行数:33,代码来源:allPythonContent.py

示例5: print

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import move_node [as 别名]
sub_t = tree.subtree('diane')
sub_t.show()
print('\n') 

print("#"*4 + "Children of Diane")
print tree.is_branch('diane')
print('\n')

print("#"*4 + "OOhh~ new members enter Jill's family")
new_tree = Tree()
new_tree.create_node("n1", 1)  # root node
new_tree.create_node("n2", 2, parent=1)
new_tree.create_node("n3", 3, parent=1)
tree.paste('jill', new_tree)
tree.show()
print('\n')

print("#"*4 + "We are sorry they are gone accidently :(")
tree.remove_node(1)
tree.show()
print('\n')

print("#"*4 + "Now Jill moves to live with Grand-x-father Harry")
tree.move_node('jill', 'harry')
tree.show()
print('\n')

print("#"*4 + "A big family for George to talk to Grand-x-father Harry")
for node in tree.rsearch('george', filter=lambda x: x != 'harry'):
    print node
print('\n')
开发者ID:techdragon,项目名称:pyTree-1,代码行数:33,代码来源:family_tree.py

示例6: toDEP

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import move_node [as 别名]

#.........这里部分代码省略.........

        #
        # construction du head_tree

        head_tree = [-1] * self.treeNS.size()
        # pour chaque noeud (non EDU/feuille) en partant de la plus grande profondeur dans l'arbre
        for d in range(len(id_nodes_depth) - 1, -1, -1):
            for id_node in id_nodes_depth[d]:
                node = self.treeNS.get_node(id_node)
                node_left = self.treeNS.get_node(node.fpointer[0])
                node_right = self.treeNS.get_node(node.fpointer[1])
                if node_left.tag == "N":
                    if head_tree[node_left.identifier] == -1:
                        identifier = node_left.identifier
                    else:
                        identifier = head_tree[node_left.identifier]
                else:
                    if head_tree[node_right.identifier] == -1:
                        identifier = node_right.identifier
                    else:
                        identifier = head_tree[node_right.identifier]
                head_tree[id_node] = identifier
        # print head_tree

        ###############################
        # Etape 2 : construction du DEP

        #
        # construction du DEP

        # init
        # root est le premier noeud de head
        # pour chaque EDU son père est le root dans DEP
        dep_tree = Tree()
        id_root = head_tree[0]
        root = self.tree.get_node(id_root)
        # dep_tree.create_node(root.tag, root.identifier)
        dep_tree.create_node(root.tag, root.identifier)
        for id_EDU in xrange(len(head_tree)):
            if head_tree[id_EDU] == -1 and id_EDU != id_root:
                node = self.tree.get_node(id_EDU)
                # dep_tree.create_node(node.tag, node.identifier, parent=id_root)
                # dep_tree.create_node(str(id_EDU), node.identifier, parent=id_root)
                dep_tree.create_node(node.tag, node.identifier, parent=id_root)

        # print '//////////////////////'
        # print 'EDU', id_root
        # pour chaque EDU
        for id_EDU in xrange(len(head_tree)):
            if head_tree[id_EDU] == -1 and id_EDU != id_root:

                EDU_NS = self.treeNS.get_node(id_EDU)
                # print '.......................'
                # print 'EDU', id_EDU
                # print 'TAG', EDU_NS.tag

                if EDU_NS.tag == "N":
                    # parcours en largeur jusqu'à trouver un S avec un head donc qui soit pas EDU
                    id_nodes = [EDU_NS.identifier]
                    visited = [False] * self.treeNS.size()
                    while id_nodes:
                        id_node = id_nodes.pop(0)
                        EDU = self.tree.get_node(id_node)
                        # print 'visited EDU', EDU.identifier
                        visited[EDU.identifier] = True
                        # cas d'arret
                        head_EDU = head_tree[EDU.identifier] == -1
                        head_EDU = False
                        node_tag = self.treeNS.get_node(EDU.identifier).tag
                        # print '  head_EDU', head_EDU
                        # print '  node_tag', node_tag
                        if not head_EDU and node_tag == "S":
                            break
                        if EDU.bpointer:
                            if not visited[EDU.bpointer]:
                                id_nodes.append(EDU.bpointer)
                        if EDU.fpointer:  # sécurité
                            if not visited[EDU.fpointer[0]]:
                                id_nodes.append(EDU.fpointer[0])
                            if not visited[EDU.fpointer[1]]:
                                id_nodes.append(EDU.fpointer[1])

                    # puis ajouter au DEP comme enfant du head du parent du noeud S
                    id_head = head_tree[EDU.bpointer]

                # si parent S
                else:
                    # parcours en largeur des ancêtre jusqu'à trouver un ancêtre avec un head
                    parent = self.treeNS.get_node(EDU_NS.bpointer)
                    id_head = head_tree[parent.identifier]

                # puis ajouter au DEP comme enfant de ce head
                if id_EDU != id_head:
                    dep_tree.move_node(id_EDU, id_head)
                EDU = self.tree.get_node(id_EDU)
                # print '---- ajout de',EDU.identifier,' à',id_head
                # if id_EDU == id_head:
                # dep_tree.show()

        return dep_tree
开发者ID:niki-rohani,项目名称:Automatic_summarization_using_RST_DT,代码行数:104,代码来源:rst2dep.py


注:本文中的treelib.Tree.move_node方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。