code: def get_labeled_corpus() -> None:
      """Loops through the files with alignment results in each semiotic class subfolder,
      collects a mapping from (semiotic class, spoken, written) to the segmented written form,
           which is aligned one-to-one to spoken words.
      Then loops through the files in Google TN Dataset format to get the labeled data for ThutmoseTaggerModel.
      It extracts the whole sentences and substitutes the semiotic spans to their aligned form from the dictionary.
      """
  
      if not os.path.exists(args.data_dir):
          raise ValueError(f"Data dir {args.data_dir} does not exist")
  
      keys2replacements = {}
      alignment_files = glob.glob(
          args.giza_dir + "/*/" + args.alignment_filename
      )
      if len(alignment_files) == 0:
          raise ValueError(
              "Did not found any such files: "
              + args.giza_dir
              + "/*/"
              + args.alignment_filename
          )
      for af in alignment_files:
          with open(af, "r", encoding="utf-8") as f:
              for line in f:
                  cls, src, dst, replacements = line.strip().split("\t")
                  key = cls + "\t" + dst + "\t" + src
                  if (
                      key in keys2replacements
                      and keys2replacements[key] != replacements
                  ):
                      logging.warning(
                          "keys2replacements[key] != replacements",
                          keys2replacements[key],
                          replacements,
                      )
                  keys2replacements[key] = replacements
      print(
          "size of phrase-to-replacements dictionary =",
          len(keys2replacements),
      )
      out = open(args.out_filename, "w", encoding="utf-8")
      input_paths = sorted(
          [
              os.path.join(args.data_dir, f)
              for f in os.listdir(args.data_dir)
          ]
      )
      for inputname in input_paths:
          process_file_itn(inputname, out, keys2replacements)
      out.close()
  
file_path: NeMo/examples/nlp/text_normalization_as_tagging/dataset_preparation/prepare_corpora_after_alignment.py
imports: import glob
  import os
  from argparse import ArgumentParser
  from collections import Counter
  from typing import Dict, Optional, TextIO, Tuple
  from nemo.collections.nlp.data.text_normalization_as_tagging.utils import get_src_and_dst_for_alignment
  from nemo.utils import logging
label_desc: Use image node_id 5 for calling a global function with example usage: get_labeled_corpus() without return types