Support arbitrary N-gram in extended mode