def get_ngrams(s, ngmin, ngmax, separator="",
               bos="<", eos=">", suffix="", flatten=True):
    """ For the given sequence s. Return all ngrams in range ngmin-ngmax.
        spearator is useful for readability
        bos/eos symbols are added to indicate beginning and end of seqence
        suffix is an arbitrary string useful for distinguishing
                in case differernt types of ngrams are used
        if flatten is false, a list of lists is returned where the
                first element contains the ngrams of size ngmin
                and the last contains the ngrams of size ngmax
    """

    # return a single dummy feature if there are no applicable ngrams
    # probably resulting in a mojority-class classifier
    if ngmax == 0 or (ngmax - ngmin < 0) :
        return ['__dummy__']

    ngrams = [[] for x in range(1, ngmax + 1)]
    s = [bos] + s + [eos]
    for i, ch in enumerate(s):
        for ngsize in range(ngmin, ngmax + 1):
            if (i + ngsize) <= len(s):
                ngrams[ngsize - 1].append(
                        separator.join(s[i:i+ngsize]) + suffix)
    if flatten:
        ngrams = [ng for nglist in ngrams for ng in nglist]
    return ngrams