docs: def _create_clause_based_dep_links( orig_text, layer=LAYER_CONLL ):
      '''  Rewrites dependency links in the text from sentence-based linking to clause-
          based linking: 
            *) words which have their parent outside-the-clause will become root 
               nodes (will obtain link value -1), and 
            *) words which have their parent inside-the-clause will have parent index
               according to word indices inside the clause;
           
      '''
      sent_start_index = 0
      for sent_text in orig_text.split_by( SENTENCES ):
          # 1) Create a mapping: from sentence-based dependency links to clause-based dependency links
          mapping = dict()
          cl_ind  = sent_text.clause_indices
          for wid, word in enumerate(sent_text[WORDS]):
              firstSyntaxRel = sent_text[layer][wid][PARSER_OUT][0]
              parentIndex    = firstSyntaxRel[1]
              if parentIndex != -1:
                  if cl_ind[parentIndex] != cl_ind[wid]:
                      # Parent of the word is outside the current clause: make root 
                      # node from the current node 
                      mapping[wid] = -1
                  else:
                      # Find the beginning of the clause 
                      clause_start = cl_ind.index( cl_ind[wid] )
                      # Find the index of parent label in the clause
                      j = 0
                      k = 0
                      while clause_start + j < len(cl_ind):
                          if clause_start + j == parentIndex:
                              break
                          if cl_ind[clause_start + j] == cl_ind[wid]:
                              k += 1
                          j += 1
                      assert clause_start + j < len(cl_ind), '(!) Parent index not found for: '+str(parentIndex)
                      mapping[wid] = k
              else:
                  mapping[wid] = -1
          # 2) Overwrite old links with new ones
          for local_wid in mapping.keys():
              global_wid = sent_start_index + local_wid
              for syntax_rel in orig_text[layer][global_wid][PARSER_OUT]:
                  syntax_rel[1] = mapping[local_wid]
          # 3) Advance the index for processing the next sentence
          sent_start_index += len(cl_ind)
      return orig_text