code: def un_chomsky_normal_form(
      tree,
      expandUnary=True,
      childChar="|",
      parentChar="^",
      unaryChar="+",
  ):
      # Traverse the tree-depth first keeping a pointer to the parent for modification purposes.
      nodeList = [(tree, [])]
      while nodeList != []:
          node, parent = nodeList.pop()
          if isinstance(node, Tree):
              # if the node contains the 'childChar' character it means that
              # it is an artificial node and can be removed, although we still need
              # to move its children to its parent
              childIndex = node.label().find(childChar)
              if childIndex != -1:
                  nodeIndex = parent.index(node)
                  parent.remove(parent[nodeIndex])
                  # Generated node was on the left if the nodeIndex is 0 which
                  # means the grammar was left factored.  We must insert the children
                  # at the beginning of the parent's children
                  if nodeIndex == 0:
                      parent.insert(0, node[0])
                      parent.insert(1, node[1])
                  else:
                      parent.extend([node[0], node[1]])
  
                  # parent is now the current node so the children of parent will be added to the agenda
                  node = parent
              else:
                  parentIndex = node.label().find(parentChar)
                  if parentIndex != -1:
                      # strip the node name of the parent annotation
                      node.set_label(node.label()[:parentIndex])
  
                  # expand collapsed unary productions
                  if expandUnary == True:
                      unaryIndex = node.label().find(unaryChar)
                      if unaryIndex != -1:
                          newNode = Tree(
                              node.label()[unaryIndex + 1 :],
                              [i for i in node],
                          )
                          node.set_label(node.label()[:unaryIndex])
                          node[0:] = [newNode]
  
              for child in node:
                  nodeList.append((child, node))
  
imports: from nltk.tree.tree import Tree
label_desc: Use image node_id 2 for calling a global function with example usage: un_chomsky_normal_form(tree, expandUnary, childChar, parentChar, unaryChar) without return types