[core][js][py] nextWord and previousWord: only necessary groups + bug fix for JS