code: def from_tree(proto_tree):
      """
      Convert a FlattenedParseTree back into a Tree
  
      returns Tree, score
        (score might be None if it is missing)
      """
      score = None
      stack = deque()
      for node in proto_tree.nodes:
          if node.HasField("score") and score is None:
              score = node.score
  
          if node.openNode:
              if (
                  len(stack) > 0
                  and isinstance(stack[-1], FlattenedParseTree.Node)
                  and stack[-1].openNode
              ):
                  raise ValueError(
                      "Got a proto with no label on a node: {}".format(
                          proto_tree
                      )
                  )
              stack.append(node)
              continue
          if not node.closeNode:
              child = Tree(label=node.value)
              # TODO: do something with the score
              stack.append(child)
              continue
  
          # must be a close operation...
          if len(stack) <= 1:
              raise ValueError(
                  "Got a proto with too many close operations: {}".format(
                      proto_tree
                  )
              )
          # on a close operation, pop until we hit the open
          # then turn everything in that span into a new node
          children = []
          nextNode = stack.pop()
          while not isinstance(nextNode, FlattenedParseTree.Node):
              children.append(nextNode)
              nextNode = stack.pop()
          if len(children) == 0:
              raise ValueError(
                  "Got a proto with an open immediately followed by a close: {}".format(
                      proto_tree
                  )
              )
          children.reverse()
          label = children[0]
          children = children[1:]
          subtree = Tree(label=label.label, children=children)
          stack.append(subtree)
  
      if len(stack) > 1:
          raise ValueError(
              "Got a proto which does not close all of the nodes: {}".format(
                  proto_tree
              )
          )
      tree = stack.pop()
      if not isinstance(tree, Tree):
          raise ValueError(
              "Got a proto which was just one Open operation: {}".format(
                  proto_tree
              )
          )
      return tree, score
  
imports: from collections import deque
  import subprocess
  from stanza.models.common.utils import misc_to_space_after
  from stanza.models.constituency.parse_tree import Tree
  from stanza.protobuf import DependencyGraph, FlattenedParseTree
  from stanza.server.client import resolve_classpath
label_desc: Use image node_id 4 for calling a global function with example usage: from_tree(proto_tree) and returns: tree,  score