code: def EnsureStructurallyNeededNgramsExist(self):
      # makes sure that if an n-gram like (6, 7, 8) -> 9 exists,
      # then counts exist for (7, 8) -> 9 and (8,) -> 9.  It does so
      # by adding zero counts where such counts were absent.
      # [note: () -> 9 is guaranteed anyway by the backoff method, if
      # we have a unigram state].
      if args.verbose >= 1:
          num_ngrams_initial = self.GetNumNgrams()
      for n in reversed(
          list(range(args.no_backoff_ngram_order, args.ngram_order))
      ):
          for hist, counts_for_hist in self.counts[n].items():
              # This loop ensures that if we have an n-gram like (6, 7, 8) -> 9,
              # then, say, (7, 8) -> 9 and (8) -> 9 exist.
              reduced_hist = hist
              for m in reversed(
                  list(range(args.no_backoff_ngram_order, n))
              ):
                  reduced_hist = reduced_hist[
                      1:
                  ]  # shift an element off
                  # the history.
                  counts_for_backoff_hist = self.counts[m][reduced_hist]
                  for word in counts_for_hist.word_to_count.keys():
                      counts_for_backoff_hist.word_to_count[word] += 0
              # This loop ensures that if we have an n-gram like (6, 7, 8) -> 9,
              # then, say, (6, 7) -> 8 and (6) -> 7 exist.  This will be needed
              # for FST representations of the ARPA LM.
              reduced_hist = hist
              for m in reversed(
                  list(range(args.no_backoff_ngram_order, n))
              ):
                  this_word = reduced_hist[-1]
                  reduced_hist = reduced_hist[
                      :-1
                  ]  # pop an element off the
                  # history
                  counts_for_backoff_hist = self.counts[m][reduced_hist]
                  counts_for_backoff_hist.word_to_count[this_word] += 0
      if args.verbose >= 1:
          print(
              "make_phone_lm.py: in EnsureStructurallyNeededNgramsExist(), "
              "added {0} n-grams".format(
                  self.GetNumNgrams() - num_ngrams_initial
              ),
              file=sys.stderr,
          )
  
imports: import argparse
  import math
  import sys
  from collections import defaultdict
label_desc: Use image node_id 10 for calling the NgramCounts obj's underlying member method code with example usage: obj.EnsureStructurallyNeededNgramsExist() without return types