code: def update_manifest_with_spellmapper_corrections(
      input_manifest_name: str,
      short2full_name: str,
      output_manifest_name: str,
      spellmapper_results_name: str,
      min_prob: float = 0.5,
      replace_hyphen_to_space: bool = True,
      field_name: str = "pred_text",
      use_dp: bool = True,
      ngram_mappings: Union[str, None] = None,
      min_dp_score_per_symbol: float = -1.5,
  ) -> None:
      """Post-process SpellMapper predictions and write corrected sentence to the specified field of nemo manifest.
      The previous content of this field will be copied to "*_before_correction" field.
      If the sentence was split into fragments before running SpellMapper, all replacements will be first gathered together and then applied to the original long sentence.
      Args:
          input_manifest_name: input nemo manifest;
          short2full_name: text file with two columns: short_sent \t full_sent;
          output_manifest_name: output nemo manifest;
          spellmapper_results_name: text file with SpellMapper inference results;
          min_prob: threshold on replacement probability;
          replace_hyphen_to_space: if True, hyphens in replacements will be converted to spaces;
          field_name: name of json field whose text we want to correct;
          use_dp: bool = If True, additional replacement filtering will be applied using dynamic programming (works slow);
          ngram_mappings: file with n-gram mappings, only needed if use_dp=True
          min_dp_score_per_symbol: threshold on dynamic programming sum score averaged by hypothesis length
      """
      short2full_sent = defaultdict(list)
      sent2corrections = defaultdict(dict)
      with open(short2full_name, "r", encoding="utf-8") as f:
          for line in f:
              s = line.strip()
              short_sent, full_sent = s.split("\t")
              short2full_sent[short_sent].append(full_sent)
              sent2corrections[full_sent] = []
  
      spellmapper_results = read_spellmapper_predictions(
          spellmapper_results_name
      )
      dp_data = None
      if use_dp:
          dp_data = load_ngram_mappings_for_dp(ngram_mappings)
  
      for text, replacements, _ in spellmapper_results:
          short_sent = text
          if short_sent not in short2full_sent:
              continue
          # it can happen that one short sentence occurred in multiple full sentences
          for full_sent in short2full_sent[short_sent]:
              offset = full_sent.find(short_sent)
              for begin, end, candidate, prob in replacements:
                  sent2corrections[full_sent].append(
                      (begin + offset, end + offset, candidate, prob)
                  )
  
      out = open(output_manifest_name, "w", encoding="utf-8")
      with open(input_manifest_name, "r", encoding="utf-8") as f:
          for line in f:
              record = json.loads(line.strip())
              sent = record[field_name]
              record[field_name + "_before_correction"] = record[
                  field_name
              ]
              if sent in sent2corrections:
                  record[field_name] = apply_replacements_to_text(
                      sent,
                      sent2corrections[sent],
                      min_prob=min_prob,
                      replace_hyphen_to_space=replace_hyphen_to_space,
                      dp_data=dp_data,
                      min_dp_score_per_symbol=min_dp_score_per_symbol,
                  )
              out.write(json.dumps(record) + "\n")
      out.close()
  
imports: import json
  import math
  import random
  import re
  from collections import defaultdict, namedtuple
  from typing import Dict, List, Set, Tuple, Union
  import numpy
  from numba import jit
label_desc: Use image node_id 13 for calling a global function with example usage: update_manifest_with_spellmapper_corrections(input_manifest_name, short2full_name, output_manifest_name, spellmapper_results_name, min_prob, replace_hyphen_to_space, field_name, use_dp, ngram_mappings, min_dp_score_per_symbol) without return types