code: def process_nodes(root_id, words, nodes, visited):
      """
      Given a root_id, a map of words, and a map of nodes, construct a Tree
  
      visited is a set of string ids and mutates over the course of the recursive call
      """
      if root_id in visited:
          raise ValueError("Loop in the tree!")
      visited.add(root_id)
  
      if root_id in words:
          word = words[root_id]
          # big brain move: put the root_id here so we can use that to
          # check the sorted order when we are done
          word_node = Tree(label=root_id)
          tag_node = Tree(label=word.tag, children=word_node)
          return tag_node
      elif root_id in nodes:
          node = nodes[root_id]
          children = [
              process_nodes(child, words, nodes, visited)
              for child in node.children
          ]
          return Tree(label=node.label, children=children)
      else:
          raise BrokenLinkError("Unknown id! {}".format(root_id))
  
file_path: stanza/stanza/utils/datasets/constituency/convert_arboretum.py
imports: from collections import namedtuple
  import io
  import xml.etree.ElementTree
  from tqdm import tqdm
  from stanza.models.constituency.parse_tree import Tree
  from stanza.server import tsurgeon
label_desc: Use image node_id 2 for calling a global function with example usage: process_nodes(root_id, words, nodes, visited) and returns: tag_node, Tree