'Whitespace sensitive char-n-gram tokenization.
Tokenize text_document into a sequence of character n-grams
operating only inside word boundaries. n-grams at the edges
of words are padded with space.'

def _char_wb_ngrams(self, text_document):

    text_document = self._white_spaces.sub(u'    ', text_document)
    (min_n, max_n) = self.ngram_range
    ngrams = []
    ngrams_append = ngrams.append
    for w in text_document.split():
        w = ((u'    ' + w) + u'    ')
        w_len = len(w)
        for n in xrange(min_n, (max_n + 1)):
            offset = 0
            ngrams_append(w[offset:(offset + n)])
            while ((offset + n) < w_len):
                offset += 1
                ngrams_append(w[offset:(offset + n)])
            if (offset == 0):
                break
    return ngrams
