code: def process_tree(sentence):
      """
      Convert a single ET element representing a Tiger tree to a parse tree
      """
      sentence = sentence.getroot()
      sent_id = sentence.get("id")
      if sent_id is None:
          raise ValueError(
              "Tree {} does not have an id".format(sent_idx)
          )
      if len(sentence) > 1:
          raise ValueError(
              "Longer than expected number of items in {}".format(
                  sent_id
              )
          )
      graph = sentence.find("graph")
      if not graph:
          raise ValueError(
              "Unexpected tree structure in {} : top tag is not 'graph'".format(
                  sent_id
              )
          )
  
      root_id = graph.get("root")
      if not root_id:
          raise ValueError("Tree has no root id in {}".format(sent_id))
  
      terminals = graph.find("terminals")
      if not terminals:
          raise ValueError("No terminals in tree {}".format(sent_id))
      # some Arboretum graphs have two sets of nonterminals,
      # apparently intentionally, so we ignore that possible error
      nonterminals = graph.find("nonterminals")
      if not nonterminals:
          raise ValueError("No nonterminals in tree {}".format(sent_id))
  
      # read the words.  the words have ids, text, and tags which we care about
      words = {}
      for word in terminals:
          if word.tag == "parentes-udeladt" or word.tag == "note":
              continue
          if word.tag != "t":
              raise ValueError(
                  "Unexpected tree structure in {} : word with tag other than t".format(
                      sent_id
                  )
              )
          word_id = word.get("id")
          if not word_id:
              raise ValueError("Word had no id in {}".format(sent_id))
          word_text = word.get("word")
          if not word_text:
              raise ValueError("Word had no text in {}".format(sent_id))
          word_pos = word.get("pos")
          if not word_pos:
              raise ValueError("Word had no pos in {}".format(sent_id))
          words[word_id] = Word(word_text, word_pos)
  
      # read the nodes.  the nodes have ids, labels, and children
      # some of the edges are labeled "secedge".  we ignore those
      nodes = {}
      for nt in nonterminals:
          if nt.tag != "nt":
              raise ValueError(
                  "Unexpected tree structure in {} : node with tag other than nt".format(
                      sent_id
                  )
              )
          nt_id = nt.get("id")
          if not nt_id:
              raise ValueError("NT has no id in {}".format(sent_id))
          nt_label = nt.get("cat")
          if not nt_label:
              raise ValueError("NT has no label in {}".format(sent_id))
  
          children = []
          for child in nt:
              if child.tag != "edge" and child.tag != "secedge":
                  raise ValueError(
                      "NT has unexpected child in {} : {}".format(
                          sent_id, child.tag
                      )
                  )
              if child.tag == "edge":
                  child_id = child.get("idref")
                  if not child_id:
                      raise ValueError(
                          "Child is missing an id in {}".format(sent_id)
                      )
                  children.append(child_id)
          nodes[nt_id] = Node(nt_label, children)
  
      if root_id not in nodes:
          raise ValueError(
              "Could not find root in nodes in {}".format(sent_id)
          )
  
      tree = process_nodes(root_id, words, nodes, set())
      return tree, words
  
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 5 for calling a global function with example usage: process_tree(sentence) and returns: tree,  words