ease/util_functions.py
def ngrams(tokens, min_n, max_n):
    """
    Generates ngrams(word sequences of fixed length) from an input token sequence.
    tokens is a list of words.
    min_n is the minimum length of an ngram to return.
    max_n is the maximum length of an ngram to return.
    returns a list of ngrams (words separated by a space)
    """
    all_ngrams = list()
    n_tokens = len(tokens)
    for i in xrange(n_tokens):
        for j in xrange(i + min_n, min(n_tokens, i + max_n) + 1):
            all_ngrams.append(" ".join(tokens[i:j]))
    return all_ngrams
def ngrams(tokens, min_n, max_n):
    """
    Generates ngrams(word sequences of fixed length) from an input token sequence.
    tokens is a list of words.
    min_n is the minimum length of an ngram to return.
    max_n is the maximum length of an ngram to return.
    returns a list of ngrams (words separated by a space)
    """
    all_ngrams = list()
    n_tokens = len(tokens)
    for i in xrange(n_tokens):
        for j in xrange(i + min_n, min(n_tokens, i + max_n) + 1):
            all_ngrams.append(" ".join(tokens[i:j]))
    return all_ngrams
def ngrams ( tokens , min_n , max_n ) : all_ngrams = list ( ) n_tokens = len ( tokens ) for i in xrange ( n_tokens ) : for j in xrange ( i + min_n , min ( n_tokens , i + max_n ) + 1 ) : all_ngrams . append ( " " . join ( tokens [ i : j ] ) ) return all_ngrams
Generates ngrams(word sequences of fixed length) from an input token sequence.
    tokens is a list of words.
    min_n is the minimum length of an ngram to return.
    max_n is the maximum length of an ngram to return.
    returns a list of ngrams (words separated by a space)
Generates ngrams ( word sequences of fixed length ) from an input token sequence . tokens is a list of words . min_n is the minimum length of an ngram to return . max_n is the maximum length of an ngram to return . returns a list of ngrams ( words separated by a space )