Integrated ngram function