code: def align(self, referencewords, datatuple):
          
          targetwords = []
          for i, (word,lemma,postag) in enumerate(zip(datatuple[0],datatuple[1],datatuple[2])):
              if word:
                  subwords = word.split("_")
                  for w in subwords: #split multiword expressions
                      targetwords.append( (w, lemma, postag, i, len(subwords) > 1 ) ) #word, lemma, pos, index, multiword? 
  
          referencewords = [ w.lower() for w in referencewords ]          
          alignment = []
          for i, referenceword in enumerate(referencewords):
              found = False
              best = 0  
              distance = 999999          
              for j, (targetword, lemma, pos, index, multiword) in enumerate(targetwords):
                  if referenceword == targetword and abs(i-j) < distance:
                      found = True
                      best = j
                      distance = abs(i-j)
  
              if found:
                  alignment.append(targetwords[best])
              else:                
                  alignment.append((None,None,None,None,False)) #no alignment found        
          
          return alignment
docs: align the reference sentence with the tagged data