code: def match_ngrams(sentence_ngrams, ngram_map, debug=False):
      """
      Check if there is a SINGLE matching sentence in the ngram_map for these ngrams
  
      If an ngram shows up in multiple sentences, that is okay, but we ignore that info
      If an ngram shows up in just one sentence, that is considered the match
      If a different ngram then shows up in a different sentence, that is a problem
      TODO: taking the intersection of all non-empty matches might be better
      """
      if debug:
          print("NGRAMS FOR DEBUG SENTENCE:")
      potential_match = None
      unknown_ngram = 0
      for ngram in sentence_ngrams:
          con_matches = ngram_map[ngram]
          if debug:
              print("{} matched {}".format(ngram, len(con_matches)))
          if len(con_matches) == 0:
              unknown_ngram += 1
              continue
          if len(con_matches) > 1:
              continue
          # get the one & only element from the set
          con_match = next(iter(con_matches))
          if debug:
              print("  {}".format(con_match))
          if potential_match is None:
              potential_match = con_match
          elif potential_match != con_match:
              return None
      if unknown_ngram > len(sentence_ngrams) / 2:
          return None
      return potential_match
  
imports: from collections import defaultdict, deque, namedtuple
  import itertools
  import os
  import re
  import sys
  from tqdm import tqdm
  from stanza.models.constituency.tree_reader import read_trees, UnclosedTreeError, ExtraCloseTreeError
  from stanza.server import tsurgeon
  from stanza.utils.conll import CoNLL
  from stanza.utils.datasets.constituency.utils import SHARDS, write_dataset
  import stanza.utils.default_paths
label_desc: Use image node_id 6 for calling a global function with example usage: match_ngrams(sentence_ngrams, ngram_map, debug) and returns: potential_match, None, None