code: def convert_file(
      orig_file,
      new_file,
      fix_errors=True,
      convert_brackets=False,
      updated_tagset=False,
  ):
      """
      :param orig_file: original directory storing original trees
      :param new_file: new directory storing formatted constituency trees
      This function writes new trees to the corresponding files in new_file
      """
      if updated_tagset:
          weird_labels = WEIRD_LABELS_2023
      else:
          weird_labels = WEIRD_LABELS
      errors = defaultdict(list)
      with open(orig_file, "r", encoding="utf-8") as reader, open(
          new_file, "w", encoding="utf-8"
      ) as writer:
          content = reader.readlines()
          # Tree string will only be written if the currently read
          # tree is a valid tree. It will not be written if it
          # does not have a '(' that signifies the presence of constituents
          tree = ""
          reading_tree = False
          for line_idx, line in enumerate(content):
              line = " ".join(line.split())
              if line == "":
                  continue
              elif line == "<s>" or line.startswith("<s id="):
                  tree = ""
                  tree += "(ROOT "
                  reading_tree = True
              elif line == "</s>" and reading_tree:
                  # one tree in 25432.prd is not valid because
                  # it is just a bunch of blank lines
                  if tree.strip() == "(ROOT":
                      errors["empty"].append(
                          "Empty tree in {} line {}".format(
                              orig_file, line_idx
                          )
                      )
                      continue
                  tree += ")\n"
                  parity = count_paren_parity(tree)
                  if parity > 0:
                      errors["unclosed"].append(
                          "Unclosed tree from {} line {}: |{}|".format(
                              orig_file, line_idx, tree
                          )
                      )
                      continue
                  if parity < 0:
                      errors["extra_parens"].append(
                          "Extra parens at end of tree from {} line {} for having extra parens: {}".format(
                              orig_file, line_idx, tree
                          )
                      )
                      continue
                  if convert_brackets:
                      tree = tree.replace("RBKT", "-RRB-").replace(
                          "LBKT", "-LRB-"
                      )
                  try:
                      # test that the tree can be read in properly
                      processed_trees = read_trees(tree)
                      if len(processed_trees) > 1:
                          errors["multiple"].append(
                              "Multiple trees in one xml annotation from {} line {}".format(
                                  orig_file, line_idx
                              )
                          )
                          continue
                      if len(processed_trees) == 0:
                          errors["empty"].append(
                              "Empty tree in {} line {}".format(
                                  orig_file, line_idx
                              )
                          )
                          continue
                      if not processed_trees[
                          0
                      ].all_leaves_are_preterminals():
                          errors["untagged_leaf"].append(
                              "Tree with non-preterminal leaves in {} line {}: {}".format(
                                  orig_file, line_idx, tree
                              )
                          )
                          continue
                      # Unify the labels
                      if fix_errors:
                          tree = unify_label(tree)
  
                      # TODO: this block eliminates 3 trees from VLSP-22
                      # maybe those trees can be salvaged?
                      bad_label = False
                      for weird_label in weird_labels:
                          if tree.find(weird_label) >= 0:
                              bad_label = True
                              errors[weird_label].append(
                                  "Weird label {} from {} line {}: {}".format(
                                      weird_label,
                                      orig_file,
                                      line_idx,
                                      tree,
                                  )
                              )
                              break
                      if bad_label:
                          continue
  
                      writer.write(tree)
                      reading_tree = False
                      tree = ""
                  except MixedTreeError:
                      errors["mixed"].append(
                          "Mixed leaves and constituents from {} line {}: {}".format(
                              orig_file, line_idx, tree
                          )
                      )
                  except UnlabeledTreeError:
                      errors["unlabeled"].append(
                          "Unlabeled nodes in tree from {} line {}: {}".format(
                              orig_file, line_idx, tree
                          )
                      )
              else:  # content line
                  if is_valid_line(line) and reading_tree:
                      tree += line
                  elif reading_tree:
                      errors["invalid"].append(
                          "Invalid tree error in {} line {}: |{}|, rejected because of line |{}|".format(
                              orig_file, line_idx, tree, line
                          )
                      )
                      reading_tree = False
  
      return errors
  
file_path: stanza/stanza/utils/datasets/constituency/vtb_convert.py
imports: import argparse
  import os
  from collections import defaultdict
  from stanza.models.constituency.tree_reader import read_trees, MixedTreeError, UnlabeledTreeError
label_desc: Use image node_id 4 for calling a global function with example usage: convert_file(orig_file, new_file, fix_errors, convert_brackets, updated_tagset) and returns: errors