more general functional n gram