code: def extract(
      f_start,
      f_end,
      e_start,
      e_end,
      alignment,
      f_aligned,
      srctext,
      trgtext,
      srclen,
      trglen,
      max_phrase_length,
  ):
      """
      This function checks for alignment point consistency and extracts
      phrases using the chunk of consistent phrases.
  
      A phrase pair (e, f ) is consistent with an alignment A if and only if:
  
      (i) No English words in the phrase pair are aligned to words outside it.
  
             ∀e i ∈ e, (e i , f j ) ∈ A ⇒ f j ∈ f
  
      (ii) No Foreign words in the phrase pair are aligned to words outside it.
  
              ∀f j ∈ f , (e i , f j ) ∈ A ⇒ e i ∈ e
  
      (iii) The phrase pair contains at least one alignment point.
  
              ∃e i ∈ e  ̄ , f j ∈ f  ̄ s.t. (e i , f j ) ∈ A
  
      :type f_start: int
      :param f_start: Starting index of the possible foreign language phrases
      :type f_end: int
      :param f_end: End index of the possible foreign language phrases
      :type e_start: int
      :param e_start: Starting index of the possible source language phrases
      :type e_end: int
      :param e_end: End index of the possible source language phrases
      :type srctext: list
      :param srctext: The source language tokens, a list of string.
      :type trgtext: list
      :param trgtext: The target language tokens, a list of string.
      :type srclen: int
      :param srclen: The number of tokens in the source language tokens.
      :type trglen: int
      :param trglen: The number of tokens in the target language tokens.
      """
  
      if f_end < 0:  # 0-based indexing.
          return {}
      # Check if alignment points are consistent.
      for e, f in alignment:
          if (f_start <= f <= f_end) and (e < e_start or e > e_end):
              return {}
  
      # Add phrase pairs (incl. additional unaligned f)
      phrases = set()
      fs = f_start
      while True:
          fe = min(f_end, f_start + max_phrase_length - 1)
          while True:
              # add phrase pair ([e_start, e_end], [fs, fe]) to set E
              # Need to +1 in range  to include the end-point.
              src_phrase = " ".join(srctext[e_start : e_end + 1])
              trg_phrase = " ".join(trgtext[fs : fe + 1])
              # Include more data for later ordering.
              phrases.add(
                  (
                      (e_start, e_end + 1),
                      (fs, fe + 1),
                      src_phrase,
                      trg_phrase,
                  )
              )
              fe += 1
              if fe in f_aligned or fe >= trglen:
                  break
          fs -= 1
          if fs in f_aligned or fs < 0:
              break
      return phrases
  
label_desc: Use image node_id 1 for calling a global function with example usage: extract(f_start, f_end, e_start, e_end, alignment, f_aligned, srctext, trgtext, srclen, trglen, max_phrase_length) and returns: phrases, dict, dict