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


Python Tree.paste方法代码示例

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


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

示例1: merge_trees

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import paste [as 别名]
def merge_trees(t1, t2, tick):
  t = Tree()
  identifier = -tick # using negative numbers as identifiers, positive numbers are ids for the leaf nodes
  name = "new_cluster_%s" % tick
  t.create_node(name, identifier)
  t.paste(identifier, t1)
  t.paste(identifier, t2)
  return t, name
开发者ID:sacry-,项目名称:AdaptiveAgents,代码行数:10,代码来源:trees.py

示例2: create_tree

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import paste [as 别名]
def create_tree(indexed_titles, root, children=None):
  t = Tree()
  identifier = indexed_titles[root]
  t.create_node(root, identifier)
  if children:
    for sub_tree in children:
      t.paste(identifier, sub_tree)
  return t
开发者ID:sacry-,项目名称:AdaptiveAgents,代码行数:10,代码来源:trees.py

示例3: crossOver

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import paste [as 别名]
  def crossOver(individualA, individualB):
    tree = None

    while tree is None or tree.depth(tree.get_node(tree.root)) > TREE_MAX_DEPTH:
      treeA = Tree(tree = individualA.tree, deep=True)
      treeB = Tree(tree = individualB.tree, deep=True)
      regenerate_ids(treeA)
      regenerate_ids(treeB)
      removedNode = random.choice(treeA.all_nodes())
      addedNode = random.choice(treeB.all_nodes())

      addedSubtree = Tree(tree = treeB.subtree(addedNode.identifier), deep=True)

      if treeA.root == removedNode.identifier:
        tree = addedSubtree

      else:
        parent = treeA.parent(removedNode.identifier)
        treeA.remove_subtree(removedNode.identifier)
        treeA.paste(parent.identifier, addedSubtree)
        tree = treeA

    return Individual(tree)
开发者ID:liranr23,项目名称:genersi,代码行数:25,代码来源:individual.py

示例4: print

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import paste [as 别名]
#     print tree[node].tag

print(sep + "Let me introduce Diane family only:")
sub_t = tree.subtree("diane")
sub_t.show()

print(sep + "Children of Diane")
for child in tree.is_branch("diane"):
    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
开发者ID:Mondego,项目名称:pyreco,代码行数:33,代码来源:allPythonContent.py

示例5: print

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import paste [as 别名]
print("#"*4 + "Let me introduce Diane family only")
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'):
开发者ID:techdragon,项目名称:pyTree-1,代码行数:32,代码来源:family_tree.py

示例6: create_ast

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import paste [as 别名]
    def create_ast(self, filename):
        """ Create an ast for a given file

            Arguments :
                filename : The name of the file to parse
        """

        # Create parser
        if self.is_64_bit:
            opcache = opcache_parser_64.OPcacheParser(filename)
        else:
            opcache = opcache_parser.OPcacheParser(filename)

        # Create syntax tree
        ast = Tree()
        ast.create_node("script", "script")
        ast.create_node("main_op_array", "main_op_array", parent="script")
        ast.create_node("function_table", "function_table", parent="script")
        ast.create_node("class_table", "class_table", parent="script")

        # Get main structures
        main_op_array = opcache['script']['main_op_array']
        functions = opcache['script']['function_table']['buckets']
        classes = opcache['script']['class_table']['buckets']

        # Main OP array
        for idx, opcode in enumerate(main_op_array['opcodes']):
            opcode = OPcode(str(idx), opcode, main_op_array, opcache, self.is_64_bit)
            ast.paste("main_op_array", opcode)

        # Function Table
        for function in functions:

            # Create function node
            function_name = function['key']['val']
            function_id = function_name + "_function"
            ast.create_node(function_name, function_id, parent="function_table")

            # Iterate over opcodes
            op_array = function['val']['op_array']
            for idx, opcode in enumerate(op_array['opcodes']):
                opcode = OPcode(str(idx), opcode, op_array, opcache, self.is_64_bit)
                ast.paste(function_id, opcode)

        # Class Table
        for class_ in classes:

            # Check for real classes
            if class_['val']['u1']['type'] == IS_PTR:

                # Create class node
                class_name = class_['key']['val']
                class_id = class_name + "_class"
                ast.create_node(class_name, class_id, parent="class_table")

                # Function Table
                for function in class_['val']['class']['function_table']['buckets']:

                    # Create function node
                    function_name = function['key']['val']
                    class_function_id = function_name + "_class_function"
                    ast.create_node(function_name, class_function_id, parent=class_id)

                    # Iterate over opcodes
                    for idx, opcode in enumerate(function['val']['op_array']['opcodes']):
                        opcode = OPcode(str(idx), opcode, function['val']['op_array'], opcache)
                        ast.paste(class_function_id, opcode)


        return ast
开发者ID:ElectroArmy,项目名称:php7-opcache-override,代码行数:72,代码来源:opcache_disassembler.py


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