code: def reduce_operations(operations, sort=True):
      """
      Get a common source root directory and target root directory for the file paths in operations
      """
      if sort:
  
          def get_key(line):
              # operation line format: op file1 xxx file2
              parts = line.split()
              return " ".join([parts[0], parts[1], parts[-1]])
  
          operations = sorted(operations, key=get_key)
  
      # Get common root directories
      src_root_dir = os.path.dirname(
          os.path.commonprefix([line.split()[1] for line in operations])
      )
      tgt_root_dir = os.path.dirname(
          os.path.commonprefix(
              [line.split()[-1] for line in operations]
          )
      )
  
      reduced_operations = []
      reduced_operations.append(f"src_root_dir: {src_root_dir}")
      reduced_operations.append(f"tgt_root_dir: {tgt_root_dir}")
      for line in operations:
          # Get operation & operation content
          op, op_content = line.split("\t")
          src_path, *items, tgt_path = op_content.split()
          # Reduce src_path and tgt_path with common root directories
          src_path = os.path.relpath(src_path, src_root_dir)
          tgt_path = os.path.relpath(tgt_path, tgt_root_dir)
          # Write the reduced operation content
          op_content = " ".join([src_path, *items, tgt_path])
          reduced_line = f"{op}\t{op_content}"
          reduced_operations.append(reduced_line)
  
      return reduced_operations
  
file_path: textlesslib/examples/expresso/dataset/processing/create_short_segments_dataset.py
imports: import os
  from tqdm import tqdm
  import soundfile
  from pathlib import Path
  from time import time
  from collections import defaultdict
label_desc: Use image node_id 5 for calling a global function with example usage: reduce_operations(operations, sort) and returns: reduced_operations, str