code: def main():
      args = get_args()
      lang_dir = Path(args.lang_dir)
      lexicon_filename = lang_dir / "lexicon.txt"
      sil_token = args.sil_token
      sil_prob = args.sil_prob
  
      lexicon = read_lexicon(lexicon_filename)
      if args.token_list is None:
          tokens = get_tokens(lexicon)
      else:
          tokens = []
          with open(args.token_list, "r") as tl:
              for line in tl.readlines():
                  token = line.split()[0]
                  assert token not in tokens
                  tokens.append(token)
  
      words = get_words(lexicon)
  
      lexicon_disambig, max_disambig = add_disambig_symbols(lexicon)
  
      for i in range(max_disambig + 1):
          disambig = f"#{i}"
          assert disambig not in tokens
          tokens.append(f"#{i}")
  
      if "<eps>" not in tokens:
          tokens = ["<eps>"] + tokens
  
      assert "<eps>" not in words
      assert "#0" not in words
      assert "<s>" not in words
      assert "</s>" not in words
  
      words = ["<eps>", "<unk>"] + words + ["#0", "<s>", "</s>"]
  
      token2id = generate_id_map(tokens)
      word2id = generate_id_map(words)
  
      write_mapping(lang_dir / "tokens.txt", token2id)
      write_mapping(lang_dir / "words.txt", word2id)
      write_lexicon(lang_dir / "lexicon_disambig.txt", lexicon_disambig)
  
      if sil_prob == 0:
          L = lexicon_to_fst_nosil(
              lexicon,
              token2id=token2id,
              word2id=word2id,
          )
  
          L_disambig = lexicon_to_fst_nosil(
              lexicon_disambig,
              token2id=token2id,
              word2id=word2id,
              need_self_loops=True,
          )
      else:
          L = lexicon_to_fst(
              lexicon,
              token2id=token2id,
              word2id=word2id,
              sil_token=sil_token,
              sil_prob=sil_prob,
          )
  
          L_disambig = lexicon_to_fst(
              lexicon_disambig,
              token2id=token2id,
              word2id=word2id,
              sil_token=sil_token,
              sil_prob=sil_prob,
              need_self_loops=True,
          )
  
      torch.save(L.as_dict(), lang_dir / "L.pt")
      torch.save(L_disambig.as_dict(), lang_dir / "L_disambig.pt")
  
      if args.debug:
          labels_sym = k2.SymbolTable.from_file(lang_dir / "tokens.txt")
          aux_labels_sym = k2.SymbolTable.from_file(
              lang_dir / "words.txt"
          )
  
          L.labels_sym = labels_sym
          L.aux_labels_sym = aux_labels_sym
          L.draw(f"{lang_dir / 'L.svg'}", title="L.pt")
  
          L_disambig.labels_sym = labels_sym
          L_disambig.aux_labels_sym = aux_labels_sym
          L_disambig.draw(
              f"{lang_dir / 'L_disambig.svg'}", title="L_disambig.pt"
          )
  
file_path: espnet/egs2/ameboshi/svs1/pyscripts/k2/prepare_lang.py
imports: import argparse
  import math
  from collections import defaultdict
  from pathlib import Path
  from typing import Any, Dict, List, Tuple
  import k2
  import torch
  from icefall.lexicon import read_lexicon, write_lexicon
  from espnet2.utils.types import str2bool
label_desc: Use image node_id 10 for calling a global function with example usage: main() without return types