def ngrams(string, n=<NUM_LIT:3>, punctuation=PUNCTUATION, continuous=False):
def strip_punctuation(s, punctuation=set(punctuation)):<EOL><INDENT>return [w for w in s if (isinstance(w, Word) and w.string or w) not in punctuation]<EOL><DEDENT>if n <= <NUM_LIT:0>:<EOL><INDENT>return []<EOL><DEDENT>if isinstance(string, basestring):<EOL><INDENT>s = [strip_punctuation(s.split("<STR_LIT:U+0020>")) for s in tokenize(string)]<EOL><DEDENT>if isinstance(string, Sentence):<EOL><INDENT>s = [strip_punctuation(string)]<EOL><DEDENT>if isinstance(string, Text):<EOL><INDENT>s = [strip_punctuation(s) for s in string]<EOL><DEDENT>if continuous:<EOL><INDENT>s = [sum(s, [])]<EOL><DEDENT>g = []<EOL>for s in s:<EOL><INDENT>g.extend([tuple(s[i:i+n]) for i in range(len(s)-n+<NUM_LIT:1>)])<EOL><DEDENT>return g<EOL>
Returns a list of n-grams (tuples of n successive words) from the given string.
        Alternatively, you can supply a Text or Sentence object.
        With continuous=False, n-grams will not run over sentence markers (i.e., .!?).
        Punctuation marks are stripped from words.