def _get_ngrams_with_counter(segment, max_order):
    'Extracts all n-grams up to a given maximum order from an input segment.\n\n  Args:\n    segment: text segment from which n-grams will be extracted.\n    max_order: maximum length in tokens of the n-grams returned by this\n        methods.\n\n  Returns:\n    The Counter containing all n-grams upto max_order in segment\n    with a count of how many times each n-gram occurred.\n  '
    ngram_counts = collections.Counter()
    for order in xrange(1, (max_order + 1)):
        for i in xrange(0, ((len(segment) - order) + 1)):
            ngram = tuple(segment[i:(i + order)])
            ngram_counts[ngram] += 1
    return ngram_counts
Extracts all n-grams up to a given maximum order from an input segment.

Args:
  segment: text segment from which n-grams will be extracted.
  max_order: maximum length in tokens of the n-grams returned by this
      methods.

Returns:
  The Counter containing all n-grams upto max_order in segment
  with a count of how many times each n-gram occurred.
def _get_ngrams_with_counter(segment, max_order):
    'Extracts all n-grams up to a given maximum order from an input segment.\n\n  Args:\n    segment: text segment from which n-grams will be extracted.\n    max_order: maximum length in tokens of the n-grams returned by this\n        methods.\n\n  Returns:\n    The Counter containing all n-grams upto max_order in segment\n    with a count of how many times each n-gram occurred.\n  '
    ngram_counts = collections.Counter()
    for order in xrange(1, (max_order + 1)):
        for i in xrange(0, ((len(segment) - order) + 1)):
            ngram = tuple(segment[i:(i + order)])
            ngram_counts[ngram] += 1
    return ngram_counts