Skip to content

Instantly share code, notes, and snippets.

@Cowa
Last active October 21, 2015 19:35
Show Gist options
  • Select an option

  • Save Cowa/e75f0f3a4da4c4ccdb21 to your computer and use it in GitHub Desktop.

Select an option

Save Cowa/e75f0f3a4da4c4ccdb21 to your computer and use it in GitHub Desktop.
// For bigrams
tokens.sliding(2).toList
// List(List(The, blue), List(blue, sky), List(sky, is), List(is, near), List(near, the), List(the, red), List(red, koala), List(koala, near), List(near, the), List(the, blue), List(blue, sky))
// For trigrams
tokens.sliding(3).toList
// List(List(The, blue, sky), List(blue, sky, is), List(sky, is, near), List(is, near, the), List(near, the, red), List(the, red, koala), List(red, koala, near), List(koala, near, the), List(near, the, blue), List(the, blue, sky))
// For n-gram
val n = ...
tokens.sliding(n).toList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment