code: def split_files(
      org_dir,
      split_dir,
      short_name=None,
      train_size=0.7,
      dev_size=0.15,
      rotation=None,
  ):
      os.makedirs(split_dir, exist_ok=True)
  
      if train_size + dev_size >= 1.0:
          print(
              "Not making a test slice with the given ratios: train {} dev {}".format(
                  train_size, dev_size
              )
          )
  
      # Create a random shuffle list of the file names in the original directory
      file_names = create_shuffle_list(org_dir)
  
      # Create train_path, dev_path, test_path
      train_path, dev_path, test_path = create_paths(
          split_dir, short_name
      )
  
      # Set up the number of samples for each train/dev/test set
      num_samples = get_num_samples(org_dir, file_names)
      print("Found {} total samples in {}".format(num_samples, org_dir))
  
      stop_train = int(num_samples * train_size)
      if train_size + dev_size >= 1.0:
          stop_dev = num_samples
          output_limits = (stop_train, stop_dev)
          output_names = (train_path, dev_path)
          print(
              "Splitting {} train, {} dev".format(
                  stop_train, stop_dev - stop_train
              )
          )
      elif train_size + dev_size > 0.0:
          stop_dev = int(num_samples * (train_size + dev_size))
          output_limits = (stop_train, stop_dev, num_samples)
          output_names = (train_path, dev_path, test_path)
          print(
              "Splitting {} train, {} dev, {} test".format(
                  stop_train,
                  stop_dev - stop_train,
                  num_samples - stop_dev,
              )
          )
      else:
          stop_dev = 0
          output_limits = (num_samples,)
          output_names = (test_path,)
          print("Copying all {} trees to test".format(num_samples))
  
      # Count how much stuff we've written.
      # We will switch to the next output file when we're written enough
      count = 0
  
      trees = []
      for filename in file_names:
          if not filename.endswith(".mrg"):
              continue
          with open(
              os.path.join(org_dir, filename), encoding="utf-8"
          ) as reader:
              new_trees = reader.readlines()
              new_trees = [x.strip() for x in new_trees]
              new_trees = [x for x in new_trees if x]
              trees.extend(new_trees)
      # rotate the train & dev sections, leave the test section the same
      if rotation is not None and rotation[0] > 0:
          rotation_start = len(trees) * rotation[0] // rotation[1]
          rotation_end = stop_dev
          # if there are no test trees, rotation_end: will be empty anyway
          trees = (
              trees[rotation_start:rotation_end]
              + trees[:rotation_start]
              + trees[rotation_end:]
          )
      tree_iter = iter(trees)
      for write_path, count_limit in zip(output_names, output_limits):
          with open(write_path, "w", encoding="utf-8") as writer:
              # Loop through the files, which then loop through the trees and write to write_path
              while count < count_limit:
                  next_tree = next(tree_iter, None)
                  if next_tree is None:
                      raise RuntimeError(
                          "Ran out of trees before reading all of the expected trees"
                      )
                  # Write to write_dir
                  writer.write(next_tree)
                  writer.write("\n")
                  count += 1
  
imports: import os
  import argparse
  import random
label_desc: Use image node_id 4 for calling a global function with example usage: split_files(org_dir, split_dir, short_name, train_size, dev_size, rotation) without return types