def get_pieces(text, plen, overlap):
    """ Split a document into text pieces."""
    words = text.split(' ')
    s, e = 0, 0
    chunks = []
    while s < len(words):
        e = s + plen
        if len(words) - e < overlap:
            e = len(words)
        p = ' '.join(words[s:e])
        chunks.append(p)
        if e == len(words):
            break
        s = s + plen - overlap
    return chunks