label tree will again recursively label the tree
    :param n: the root node, usually d3['children'][0]
    :param lookup: the node/id lookup
977133
def label_tree(n,lookup):
    '''
    '''
    if len(n["children"]) == 0:
        leaves = [lookup[n["node_id"]]]
    else:
        leaves = reduce(lambda ls, c: ls + label_tree(c,lookup), n["children"], [])
    del n["node_id"]
    n["name"] = name = "|||".join(sorted(map(str, leaves)))
    return leaves
778205
def find(self, node_label):
        
        queue = []
        current_node = node_label
        while self.__forest[current_node] >= 0:
            queue.append(current_node)
            current_node = self.__forest[current_node]
        root_node = current_node

        # Path compression
        for n in queue:
            self.__forest[n] = root_node

        return root_node
1027819
private void initializeNamesNodesMaps(Tree t) {
    for (Tree node : t.subTreeList()) {
      Matcher m = namePattern.matcher(node.label().value());
      if (m.find()) {
        namesToNodes.put(m.group(1),node);
        nodesToNames.put(node,m.group(1));
        node.label().setValue(m.replaceFirst(""));
      }
      Matcher m1 = escapedNameChar.matcher(node.label().value());
      node.label().setValue(m1.replaceAll(nameIntroducingChar));
    }
  }
557720
def union(self, label_a, label_b):
        
        # Base case to avoid work
        if label_a == label_b:
            return

        # Find the tree root of each node
        root_a = self.find(label_a)
        root_b = self.find(label_b)

        # Avoid merging a tree to itself
        if root_a == root_b:
            return

        self.__internal_union(root_a, root_b)
        self.__set_counter -= 1
493243
def _recursiveSetNodePath(self, nodePath):
        
        self._nodePath = nodePath
        for childItem in self.childItems:
            childItem._recursiveSetNodePath(nodePath + '/' + childItem.nodeName)
158104
def makenode(clss, symbol, *nexts):
        
        result = clss(symbol)
        for i in nexts:
            if i is None:
                continue
            if not isinstance(i, clss):
                raise NotAnAstError(i)
            result.appendChild(i)

        return result
537020
public static Tree toTree(TreebankNode node, Pair<String, MultiDimensionalMap<Integer, Integer, String>> labels)
                    throws Exception {
        List<String> tokens = tokens(node);
        Tree ret = new Tree(tokens);
        ret.setValue(node.getNodeValue());
        ret.setLabel(node.getNodeType());
        ret.setType(node.getNodeType());
        ret.setBegin(node.getBegin());
        ret.setEnd(node.getEnd());
        ret.setParse(TreebankNodeUtil.toTreebankString(node));
        if (node.getNodeTags() != null)
            ret.setTags(tags(node));
        else
            ret.setTags(Arrays.asList(node.getNodeType()));
        return ret;
    }
265603
def name(self, node, children):
        ''
        return self.env.get(node.text.strip(), -1)
1135100
def parent(self):
        
        if self == root or self == empty:
            raise NoParent
        return Name(self.labels[1:])
1355618
def depth_first_search_with_parent_data(graph, root_node = None, adjacency_lists = None):
    """"""
    ordering = []
    parent_lookup = {}
    children_lookup = defaultdict(lambda: [])

    all_nodes = graph.get_all_node_ids()
    if not all_nodes:
        return ordering, parent_lookup, children_lookup

    stack = deque()
    discovered = defaultdict(lambda: False)
    unvisited_nodes = set(all_nodes)

    if root_node is None:
        root_node = all_nodes[0]

    if adjacency_lists is None:
        adj = lambda v: graph.neighbors(v)
    else:
        adj = lambda v: adjacency_lists[v]

    # --Initialize the stack, simulating the DFS call on the root node
    stack.appendleft(root_node)
    parent_lookup[root_node] = root_node

    # We're using a non-recursive implementation of DFS, since Python isn't great for deep recursion
    while True:
        # Main DFS Loop
        while len(stack) > 0:
            u = stack.popleft()

            if not discovered[u]:
                discovered[u] = True
                if u in unvisited_nodes:
                    unvisited_nodes.remove(u)
                ordering.append(u)
                neighbors = adj(u)
                # When adding the new nodes to the stack, we want to add them in reverse order so that
                # the order the nodes are visited is the same as with a recursive DFS implementation
                for n in neighbors[::-1]:
                    if discovered[n]:
                        # If the node already exists in the discovered nodes list
                        # we don't want to re-add it to the stack
                        continue
                    stack.appendleft(n)
                    parent_lookup[n] = u
                    children_lookup[u].append(n)

        # While there are still nodes that need visiting, repopulate the stack
        if len(unvisited_nodes) > 0:
            u = unvisited_nodes.pop()
            stack.appendleft(u)
        else:
            break

    return ordering, parent_lookup, children_lookup
591508
def label( self, node ):
        """"""
        result = []
        if node.get('type'):
            result.append( node['type'] )
        if node.get('name' ):
            result.append( node['name'] )
        elif node.get('value') is not None:
            result.append( unicode(node['value'])[:32])
        if 'module' in node and not node['module'] in result:
            result.append( ' in %s'%( node['module'] ))
        if node.get( 'size' ):
            result.append( '%s'%( mb( node['size'] )))
        if node.get( 'totsize' ):
            result.append( '(%s)'%( mb( node['totsize'] )))
        parent_count = len( node.get('parents',()))
        if parent_count > 1:
            result.append( '/%s refs'%( parent_count ))
        return " ".join(result)
1278535
private String indexLabel(Entry child)
                    throws ObjectManagerException
    {
        // Step up the tree until we reach the root.
        String indexLabel = "";
        for (Entry parent = (Entry) child.getParent(); parent != null; parent = (Entry) child.getParent()) {
            if (parent.getLeft() == child)
                indexLabel = "L," + indexLabel;
            else if (parent.getRight() == child)
                indexLabel = "R," + indexLabel;
            else
                indexLabel = "Invalid," + indexLabel;
            child = parent;
        } // for...
        return indexLabel;
    }
378613
def labels(self):
        
        return [
            name for name in os.listdir(self.root)
            if os.path.isdir(os.path.join(self.root, name))
        ]
779693
def _root(self):
        
        _n = self
        while _n.parent:
            _n = _n.parent
        return _n
286709
function _labelBlankNodes(namer, element) {
  if(_isArray(element)) {
    for(var i = 0; i < element.length; ++i) {
      element[i] = _labelBlankNodes(namer, element[i]);
    }
  }
  else if(_isList(element)) {
    element['@list'] = _labelBlankNodes(namer, element['@list']);
  }
  else if(_isObject(element)) {
    // rename blank node
    if(_isBlankNode(element)) {
      element['@id'] = namer.getName(element['@id']);
    }

    // recursively apply to all keys
    var keys = Object.keys(element).sort();
    for(var ki = 0; ki < keys.length; ++ki) {
      var key = keys[ki];
      if(key !== '@id') {
        element[key] = _labelBlankNodes(namer, element[key]);
      }
    }
  }

  return element;
}
828136
def name_tree(tree):
    
    existing_names = Counter((_.name for _ in tree.traverse() if _.name))
    if sum(1 for _ in tree.traverse()) == len(existing_names):
        return
    i = 0
    existing_names = Counter()
    for node in tree.traverse('preorder'):
        name = node.name if node.is_leaf() else ('root' if node.is_root() else None)
        while name is None or name in existing_names:
            name = '{}{}'.format('t' if node.is_leaf() else 'n', i)
            i += 1
        node.name = name
        existing_names[name] += 1
322587
def copy(self):
        
        return LabeledTree(
            udepth = self.udepth,
            depth = self.depth,
            text = self.text,
            label = self.label,
            children = self.children.copy() if self.children != None else [],
            parent = self.parent)