code: def free_ngram(line, args, key, ngrams, ngrams_freq_sorted):
      # remove all the ngrams
  
      try:
          myjson = json.loads(line)
          text_buf = [myjson[key]]
      except Exception as e:
          print("Error: {}".format(e), flush=True)
          text_buf = []
  
      text_buf_ngram_free = []
      local_ngram = {}
      while len(text_buf) > 0:
          # get the first one from the buffer
          text = text_buf.pop(0)
          words, positions = get_words(text)
  
          ngram_free = True
          # find each max n-grams and check dictionary
          for i in range(len(words) - args.max_ngram_size + 1):
              check_ngram_free = check_and_clean_text(
                  args,
                  words[i : i + args.max_ngram_size],
                  ngrams,
                  text,
                  positions[i],
                  text_buf_ngram_free,
                  text_buf,
                  local_ngram,
              )
  
              # the seq is ngram free? if yes, break
              if not check_ngram_free:
                  ngram_free = False
                  break
  
              # if max ngrams doesn't match, check if any other lower n-grams
              # within max ngram macthes
              for ngram_len, _ in ngrams_freq_sorted:
                  check_ngram_free = check_and_clean_text(
                      args,
                      words[i : i + ngram_len],
                      ngrams,
                      text,
                      positions[i],
                      text_buf_ngram_free,
                      text_buf,
                      local_ngram,
                  )
  
                  # same check as above
                  if not check_ngram_free:
                      ngram_free = False
                      break
  
              # check break from lower than max ngram loop above
              if not ngram_free:
                  break
  
          # for the last max n-gram, check all the lower ngrams in it
          if ngram_free and len(words) - args.max_ngram_size > 0:
              # get the last words of the lax max ngram
              last_seq_words = words[
                  (len(words) - args.max_ngram_size) : len(words)
              ]
              last_seq_start_position = len(words) - args.max_ngram_size
  
              # check all n-grams lower than the max
              for pos, (ngram_len, _) in enumerate(ngrams_freq_sorted):
                  # ignore the max ngram as has been considered already
                  if ngram_len == args.max_ngram_size:
                      continue
  
                  # find each ngram of ngram_len in max n-grams and check
                  for i in range(len(last_seq_words) - ngram_len + 1):
                      check_ngram_free = check_and_clean_text(
                          args,
                          last_seq_words[i : i + ngram_len],
                          ngrams,
                          text,
                          positions[last_seq_start_position + i],
                          text_buf_ngram_free,
                          text_buf,
                          local_ngram,
                      )
  
                      if not check_ngram_free:
                          ngram_free = False
                          break
  
                  if not ngram_free:
                      break
  
          # texts are ngram free
          if ngram_free and not args.get_ngram_freq_only:
              text_buf_ngram_free.append(text)
  
      # check if the text has only been trimmed
      trimmed = 0
      if (
          not args.get_ngram_freq_only
          and len(text_buf_ngram_free) == 1
          and len(text_buf_ngram_free[0]) < len(myjson[key])
      ):
          trimmed = 1
  
      return text_buf_ngram_free, trimmed, myjson, local_ngram
  
imports: import argparse
  from functools import partial
  import json
  import multiprocessing
  import nltk
  import pickle
  import re
  import string
  import sys
  import time
label_desc: Use image node_id 4 for calling a global function with example usage: free_ngram(line, args, key, ngrams, ngrams_freq_sorted) and returns: text_buf_ngram_free,  trimmed,  myjson,  local_ngram