def _greedily_extract(a, s):
  """Greedily calculate extractive fragments.

  Exactly follows figure 3 in https://aclweb.org/anthology/N18-1065.
  Args:
    a: tokenized documents.
    s: tokenized summary.

  Returns:
    extractive fragments.
  """
  fs = []
  i = j = 0
  while i < len(s):
    f = []
    while j < len(a):
      if s[i] == a[j]:
        ii, jj = i, j
        while ii < len(s) and jj < len(a) and s[ii] == a[jj]:
          ii, jj = ii + 1, jj + 1
        if len(f) < (ii - i):
          f = s[i:ii]
        j = jj
      else:
        j += 1
    i, j = i + max(len(f), 1), 0
    if f:
      fs.append(f)
  return fs