ngram implementation
dictionary building and ngram