code: def match_second_degree(name_list1, name_list2):
      """
      Perform the double matching between two lists of
      possible names.
      First find the direct matches, remove them from
      the ones still to match and
      match the remaining ones using the maximum overlap.
      Returns the name
      match for each list, and the index correspondences.
  
      More subtle matching with first direct matching and then secondary
      overlap matching between list of list of potential names
      :param name_list1:
      :param name_list2:
      :return init_match1:
      :return ind_match1: Index of corresponding match in name_list2
      :return init_match2: Matching string in list2
      :return ind_match2: Index of corresponding match in name_list1
      """
      if name_list1 is None or name_list2 is None:
          return None, None, None, None
      (
          init_match1,
          init_match2,
          ind_match1,
          ind_match2,
      ) = match_first_degree(name_list1, name_list2)
      reduced_list1 = [
          names
          for names in name_list1
          if init_match1[name_list1.index(names)] == ""
      ]
      reduced_list2 = [
          names
          for names in name_list2
          if init_match2[name_list2.index(names)] == ""
      ]
      redflat_1 = [
          item for sublist in reduced_list1 for item in sublist
      ]
      indflat_1 = [
          i
          for i in range(0, len(init_match1))
          for item in name_list1[i]
          if init_match1[i] == ""
      ]
      redflat_2 = [
          item for sublist in reduced_list2 for item in sublist
      ]
      indflat_2 = [
          i
          for i in range(0, len(init_match2))
          for item in name_list2[i]
          if init_match2[i] == ""
      ]
      for i in range(0, len(name_list1)):
          if init_match1[i] == "":
              for n in name_list1[i]:
                  init_match1[i], index = __find_max_overlap_in_list(
                      n, redflat_2
                  )
                  if index >= 0:
                      ind_match1[i] = indflat_2[index]
      for i in range(0, len(name_list2)):
          if init_match2[i] == "":
              for n in name_list2[i]:
                  init_match2[i], index = __find_max_overlap_in_list(
                      n, redflat_1
                  )
                  if index >= 0:
                      ind_match2[i] = indflat_1[index]
      return init_match1, ind_match1
  
file_path: NiftyNet/niftynet/utilities/util_csv.py
imports: from __future__ import absolute_import, print_function, division
  import csv
  import os
  import sys
  from difflib import SequenceMatcher
  import numpy
  from niftynet.io.misc_io import touch_folder
  from niftynet.utilities.filename_matching import KeywordsMatching
label_desc: Use image node_id 3 for calling a global function with example usage: match_second_degree(name_list1, name_list2) and returns: init_match1,  ind_match1, None,  None,  None,  None