class_docstr: Individual fairness perturbation for person names.
class_docstr_tok: ["Individual","fairness","perturbation","for","person","names","."]
docstr: Get the substitute name for the token.
  
  The lowered version of the token must exist in self.source_names. Return
  None if self.preserve_gender tag is set, but there is no corresponding
  name in the matching gender.
docstr_tok: ["Get","the","substitute","name","for","the","token",".","The","lowered","version","of","the","token","must","exist","in","self.source_names",".","Return","None","if","self.preserve_gender","tag","is","set",",","but","there","is","no","corresponding","name","in","the","matching","gender","."]
code: def get_substitute_name(
      self, token: str, rng: Random
  ) -> Optional[str]:
      """Get the substitute name for the token.
  
      The lowered version of the token must exist in self.source_names. Return
      None if self.preserve_gender tag is set, but there is no corresponding
      name in the matching gender.
      """
      options = self.target_names
      if self.preserve_gender:
          name_gender = self.get_name_gender(token.lower())
          if name_gender:
              gendered_names_dict = self.mapping_dict[
                  self.GENDER_CATEGORY
              ]
              options = [
                  n
                  for n in self.target_names
                  if n in gendered_names_dict[name_gender]
              ]
              if not options:
                  return None  # No substitution exist if we preserve the gender
          # If we don't know the gender for the source name, we randomly pick one of the target names
      name = rng.choice(list(options))
      return name
  
imports: import os
  import re
  from collections import defaultdict
  from dataclasses import dataclass, replace
  from functools import reduce
  from pathlib import Path
  from random import Random
  from typing import Dict, List, Optional, Set
  from helm.benchmark.scenarios.scenario import Input, Instance, Reference, Output
  from helm.common.general import ensure_file_downloaded, ensure_directory_exists, match_case
  from .perturbation_description import PerturbationDescription
  from .perturbation import Perturbation
label_desc: Use image node_id 8 for calling the PersonNamePerturbation obj's underlying member method code with example usage: obj.get_substitute_name(token, rng) and returns: name, None