def n_grams(text, n, as_list=True):
    """Splits text into consecutive n-grams, e.g. pairwise, triples, etc."""
    w = text.split()
    if len(w) >= n:
        n_grams = [w[i : i + n] for i in range(len(w) - n + 1)]
        if as_list:
            return n_grams
        joined = []
        for n_gram in n_grams:
            joined.append(" ".join(n_gram))
        return joined
    return w