Resets ngram history after each document and adds refmt implementation