def _get_ngrams(segment, max_order):
ngram_counts = collections.Counter()<EOL>for order in range(<NUM_LIT:1>, max_order + <NUM_LIT:1>):<EOL><INDENT>for i in range(<NUM_LIT:0>, len(segment) - order + <NUM_LIT:1>):<EOL><INDENT>ngram = tuple(segment[i:i+order])<EOL>ngram_counts[ngram] += <NUM_LIT:1><EOL><DEDENT><DEDENT>return ngram_counts<EOL>
Extracts all n-grams upto 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.