docs: def remove_duplicate_analyses( mrf_lines, allow_to_delete_all = True ):
      ''' Removes duplicate analysis lines from mrf_lines. 
          
          Uses special logic for handling adposition analyses ('_K_ pre' && '_K_ post')
          that do not have subcategorization information:
           *) If a word has both adposition analyses, removes '_K_ pre';
           *) If a word has '_K_ post', removes it;
          Note that '_K_ pre' and '_K_ post' with subcategorization information will
          be kept.
          
          The parameter  allow_to_delete_all  specifies whether it is allowed to delete
          all analysis or not. If allow_to_delete_all == False, then one last analysis
          won't be deleted, regardless whether it should be deleted considering the 
          adposition-deletion rules;
          The original implementation corresponds to the settings allow_to_delete_all=True 
          (and this is also the default value of the parameter);
          
          Returns the input list where the removals have been applied;
      ''' 
      i = 0
      seen_analyses  = []
      analyses_count = 0
      to_delete      = []
      Kpre_index     = -1
      Kpost_index    = -1
      while ( i < len(mrf_lines) ):
          line = mrf_lines[i]
          if not line.startswith('  '): 
             if Kpre_index != -1 and Kpost_index != -1:
                # If there was both _K_pre and _K_post, add _K_pre to removables;
                to_delete.append( Kpre_index )
             elif Kpost_index != -1:
                # If there was only _K_post, add _K_post to removables;
                to_delete.append( Kpost_index )
             # Delete found duplicates
             if to_delete:
                for k, j in enumerate(sorted(to_delete, reverse=True)):
                    # If we must preserve at least one analysis, and
                    # it has been found that all should be deleted, then 
                    # keep the last one
                    if not allow_to_delete_all and \
                       analyses_count == len(to_delete) and \
                       k == len(to_delete) - 1:
                       continue
                    # Delete the analysis line
                    del mrf_lines[j]
                    i -= 1
             # Reset the memory for each new word/token
             seen_analyses = []
             analyses_count = 0
             to_delete     = []
             Kpre_index    = -1
             Kpost_index   = -1
          elif line.startswith('  '):   # the line of analysis 
             analyses_count += 1
             if line in seen_analyses:
                # Remember line that has been already seen as a duplicate
                to_delete.append( i )
             else:
                # Remember '_K pre' and '_K_ post' indices
                if re.search('/_K_\s+pre\s+//', line):
                   Kpre_index  = i
                elif re.search('/_K_\s+post\s+//', line):
                   Kpost_index = i
                # Remember that the line has already been seen
                seen_analyses.append( line )
          i += 1
      return mrf_lines