def _preprocess(doc, accent_function=None, lower=False):
    """
    Chain together an optional series of text preprocessing steps to
    apply to a document.
    """
    if lower:
        doc = doc.lower()
    if accent_function is not None:
        doc = accent_function(doc)
    return doc