class_docstr: Transformation that simulate ocr error by random values.
class_docstr_tok: ["Transformation","that","simulate","ocr","error","by","random","values","."]
docstr: Get a list of transformed tokens.
  
  :param str word: token word to transform.
  :param int n: number of transformed tokens to generate.
  :param kwargs:
  :return list replaced_tokens: replaced tokens list
docstr_tok: ["Get","a","list","of","transformed","tokens",".",":","param","str","word",":","token","word","to","transform",".",":","param","int","n",":","number","of","transformed","tokens","to","generate",".",":","param","kwargs",":",":","return","list","replaced_tokens",":","replaced","tokens","list"]
code: def _get_candidates(self, word, n=3, **kwargs):
      r"""
      Get a list of transformed tokens.
  
      :param str word: token word to transform.
      :param int n: number of transformed tokens to generate.
      :param kwargs:
      :return list replaced_tokens: replaced tokens list
  
      """
      replaced_tokens = []
      chars = self.token2chars(word)
      valid_chars_idxes = [
          idx
          for idx in range(len(chars))
          if chars[idx] in self.rules.rules
          and len(self.rules.predict(chars[idx])) > 0
      ]
      if not valid_chars_idxes:
          return []
  
      # putback sampling
      replace_char_idxes = [
          random.sample(valid_chars_idxes, 1)[0] for i in range(n)
      ]
      replace_idx_dic = {}
  
      for idx in set(replace_char_idxes):
          replace_idx_dic[idx] = replace_char_idxes.count(idx)
  
      for replace_idx in replace_idx_dic:
          sample_num = replace_idx_dic[replace_idx]
          cand_chars = self.sample_num(
              self.rules.predict(chars[replace_idx]), sample_num
          )
  
          for cand_char in cand_chars:
              replaced_tokens.append(
                  self.chars2token(
                      chars[:replace_idx]
                      + [cand_char]
                      + chars[replace_idx + 1 :]
                  )
              )
  
      return replaced_tokens
  
file_path: textflint/textflint/generation/transformation/UT/ocr.py
imports: import random
  from ...transformation import WordSubstitute
label_desc: Use image node_id 4 for calling the Ocr obj's underlying member method code with example usage: obj._get_candidates(word, n) and returns: replaced_tokens, list