NGrams - Maple Help

StringTools

 NGrams
 compute the n-grams of a string

 Calling Sequence NGrams( s, n )

Parameters

 s - string n - non-negative (32-bit) integer

Description

 • The NGrams( s, n ) command computes the ordered list of n-grams of the string s. The second argument n must be a 32-bit positive integer no larger than the length of s.
 • An n-gram of s is a substring of s consisting of exactly n contiguous characters from s.
 • The empty string $""$ has no n-grams, for any value of n.
 • Note that NGrams( s, 1 ) is equivalent to $\mathrm{Explode}\left(s\right)$.
 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{NGrams}\left("abcd",1\right)$
 $\left[{"a"}{,}{"b"}{,}{"c"}{,}{"d"}\right]$ (1)
 > $\mathrm{NGrams}\left("abcd",2\right)$
 $\left[{"ab"}{,}{"bc"}{,}{"cd"}\right]$ (2)
 > $\mathrm{NGrams}\left("abcd",3\right)$
 $\left[{"abc"}{,}{"bcd"}\right]$ (3)
 > $\mathrm{NGrams}\left("abcd",4\right)$
 $\left[{"abcd"}\right]$ (4)
 > $\mathrm{NGrams}\left("mathematics",3\right)$
 $\left[{"mat"}{,}{"ath"}{,}{"the"}{,}{"hem"}{,}{"ema"}{,}{"mat"}{,}{"ati"}{,}{"tic"}{,}{"ics"}\right]$ (5)