class_docstr: Make the first word of the surname and the preceding word form a word,
          and the last word of the name and the following word form a word
  
  Example::
  
      我朝小明走了过去 -> 我朝向明走了过去
class_docstr_tok: ["Make","the","first","word","of","the","surname","and","the","preceding","word","form","a","word",",","and","the","last","word","of","the","name","and","the","following","word","form","a","word","Example",":",":","\u6211\u671d\u5c0f\u660e\u8d70\u4e86\u8fc7\u53bb","-",">","\u6211\u671d\u5411\u660e\u8d70\u4e86\u8fc7\u53bb"]
docstr: transformation function
  
  :param str sentence: chinese sentence
  :param list label: Chinese word segmentation tag
  :param list ner_label: sentence's ner tag
  :param int n: the number of transformations
  :return list: two list include the pos which changed and the
      label which changed
docstr_tok: ["transformation","function",":","param","str","sentence",":","chinese","sentence",":","param","list","label",":","Chinese","word","segmentation","tag",":","param","list","ner_label",":","sentence","'s","ner","tag",":","param","int","n",":","the","number","of","transformations",":","return","list",":","two","list","include","the","pos","which","changed","and","the","label","which","changed"]
code: def _get_transformations(self, sentence, label, ner_label, n):
      r"""
      transformation function
  
      :param str sentence: chinese sentence
      :param list label: Chinese word segmentation tag
      :param list ner_label: sentence's ner tag
      :param int n: the number of transformations
      :return list: two list include the pos which changed and the
          label which changed
      """
      assert len(sentence) == len(label)
  
      change_pos = []
      change_list = []
      if len(ner_label):
          for ner in ner_label:
              tag, start, end = ner
              # Determine whether it is a name based on the ner tag
              # and the word segmentation tag
              if (
                  tag != "Nh"
                  or label[start] != "B"
                  or label[end] != "E"
                  or label[start + 1 : end] != ["M"] * (end - start - 1)
              ):
                  continue
              # Combine the last name and the previous n words into a word,
              # and get a list of replacement words
              s = ""
              change = []
  
              for i in range(1, 6):
                  if start < i:
                      break
                  s = sentence[start - i] + s
                  if s in self.name_dict:
                      change += self.name_dict[s]
              if len(change) > 0:
                  change_pos += [start]
                  change_list += [
                      random.sample(change, min(len(change), n))
                  ]
  
              # The name and the following n letters form a word,
              # and get a list of replacement words
              s = ""
              change = []
  
              for j in range(1, 5):
                  if end + j >= len(label):
                      break
                  s += sentence[end + j]
                  if s in self.word_end_dict:
                      change += self.word_end_dict[s]
              if len(change) > 0:
                  change_pos += [end]
                  change_list += [
                      random.sample(change, min(len(change), n))
                  ]
  
      return change_pos, change_list
  
file_path: textflint/textflint/generation/transformation/CWS/swap_name.py
imports: import random
  from ..transformation import Transformation
  from ....common.settings import NAME_PATH, WORD_LIST_PATH
  from ....common.utils.load import plain_lines_loader
  from ....common.utils.install import download_if_needed
  from ....common.utils.list_op import descartes
label_desc: Use image node_id 5 for calling the SwapName obj's underlying member method code with example usage: obj._get_transformations(sentence, label, ner_label, n) and returns: change_pos,  change_list