utility functions for calculating stuff on ngrams