code: def match_sentences(
      con_tree_map,
      con_vit_ngrams,
      dep_sentences,
      split_name,
      debug_sentence=None,
  ):
      """
      Match ngrams in the dependency sentences to the constituency sentences
  
      Then, to make sure the constituency sentence wasn't split into two
      in the UD dataset, this checks the ngrams in the reverse direction
  
      Some examples of things which don't match:
        VIT-4769 Insegnanti non vedenti, insegnanti non autosufficienti con protesi agli arti inferiori.
        this is duplicated in the original dataset, so the matching algorithm can't possibly work
  
        VIT-4796 I posti istituiti con attività di sostegno dei docenti che ottengono il trasferimento su classi di concorso;
        the correct con match should be sent_04829 but the brackets on that tree are broken
      """
      con_to_dep_matches = {}
      dep_ngram_map = build_ngrams(
          dep_sentences, DEP_PROCESS_FUNC, DEP_ID_FUNC
      )
      unmatched = 0
      bad_match = 0
      for sentence in dep_sentences:
          sentence_ngrams = extract_ngrams(sentence, DEP_PROCESS_FUNC)
          potential_match = match_ngrams(
              sentence_ngrams,
              con_vit_ngrams,
              debug_sentence is not None
              and DEP_ID_FUNC(sentence) == debug_sentence,
          )
          if potential_match is None:
              if unmatched < 5:
                  print(
                      "Could not match the following sentence: {} {}".format(
                          DEP_ID_FUNC(sentence), sentence.text
                      )
                  )
              unmatched += 1
              continue
          if potential_match not in con_tree_map:
              raise ValueError("wtf")
          con_ngrams = extract_ngrams(
              con_tree_map[potential_match], CON_PROCESS_FUNC
          )
          reverse_match = match_ngrams(con_ngrams, dep_ngram_map)
          if reverse_match is None:
              # print("Matched sentence {} to sentence {} but the reverse match failed".format(sentence.text, " ".join(con_tree_map[potential_match].leaf_labels())))
              bad_match += 1
              continue
          con_to_dep_matches[potential_match] = reverse_match
      print(
          "Failed to match %d sentences and found %d spurious matches in the %s section"
          % (unmatched, bad_match, split_name)
      )
      return con_to_dep_matches
  
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 7 for calling a global function with example usage: match_sentences(con_tree_map, con_vit_ngrams, dep_sentences, split_name, debug_sentence) and returns: con_to_dep_matches