code: def convert_ctb(input_dir, output_dir, dataset_name, version):
      input_files = glob.glob(os.path.join(input_dir, "*"))
  
      # train, dev, test
      datasets = [[], [], []]
  
      sorted_filenames = []
      for input_filename in input_files:
          base_filename = os.path.split(input_filename)[1]
          filenum = int(
              os.path.splitext(base_filename)[0].split("_")[1]
          )
          sorted_filenames.append((filenum, input_filename))
      sorted_filenames.sort()
  
      for filenum, filename in tqdm(sorted_filenames):
          if version is Version.V51:
              with open(
                  filename, errors="ignore", encoding="gb2312"
              ) as fin:
                  text = fin.read()
          else:
              with open(filename, encoding="utf-8") as fin:
                  text = fin.read()
              if text.find("<TURN>") >= 0 and text.find("</TURN>") < 0:
                  text = text.replace("<TURN>", "")
              if filenum in (4205, 4208, 4289):
                  text = text.replace("<)", "&lt;)").replace(
                      ">)", "&gt;)"
                  )
              if filenum >= 4000 and filenum <= 4411:
                  if text.find("<segment") >= 0:
                      text = text.replace(
                          "<segment id=", "<S ID="
                      ).replace("</segment>", "</S>")
                  elif text.find("<seg") < 0:
                      text = "<TEXT>\n%s</TEXT>\n" % text
                  else:
                      text = text.replace("<seg id=", "<S ID=").replace(
                          "</seg>", "</S>"
                      )
                  text = "<foo>\n%s</foo>\n" % text
              if (
                  filenum >= 5000
                  and filenum <= 5558
                  or filenum >= 6000
                  and filenum <= 6700
                  or filenum >= 7000
                  and filenum <= 7017
              ):
                  text = su_re.sub("", text)
                  if filenum in (6066, 6453):
                      text = text.replace("<", "&lt;").replace(
                          ">", "&gt;"
                      )
                  text = "<foo><TEXT>\n%s</TEXT></foo>\n" % text
          text = id_re.sub(r'<S ID="\1">', text)
          text = text.replace("&", "&amp;")
  
          try:
              xml_root = ET.fromstring(text)
          except Exception as e:
              print(text[:1000])
              raise RuntimeError(
                  "Cannot xml process %s" % filename
              ) from e
          trees = [x for x in collect_trees_s(xml_root)]
          if version is Version.V90 and len(trees) == 0:
              trees = [x for x in collect_trees_text(xml_root)]
  
          if version is Version.V51:
              trees = [
                  x[0]
                  for x in trees
                  if filenum != 414 or x[1] != "4366"
              ]
          else:
              trees = [x[0] for x in trees]
  
          trees = "\n".join(trees)
          try:
              trees = tree_reader.read_trees(trees, use_tqdm=False)
          except ValueError as e:
              print(text[:300])
              raise RuntimeError(
                  "Could not process the tree text in %s" % filename
              )
          trees = [t.prune_none().simplify_labels() for t in trees]
  
          assert len(trees) > 0, "No trees in %s" % filename
  
          if version is Version.V51:
              shard = filenum_to_shard_51(filenum)
          else:
              shard = filenum_to_shard_90(filenum)
          datasets[shard].extend(trees)
  
      write_dataset(datasets, output_dir, dataset_name)
  
file_path: stanza/stanza/utils/datasets/constituency/convert_ctb.py
imports: from enum import Enum
  import glob
  import os
  import re
  import xml.etree.ElementTree
  from stanza.models.constituency import tree_reader
  from stanza.utils.datasets.constituency.utils import write_dataset
  from stanza.utils.get_tqdm import get_tqdm
label_desc: Use image node_id 5 for calling a global function with example usage: convert_ctb(input_dir, output_dir, dataset_name, version) without return types