n
and a text sequence, then splits the sequence into
overlapping contiguous subsequences of length n
.
Syntax
Parameters
Parameter | Description | Datatype |
---|---|---|
<n> | An integer specifying the length of each n-gram. | INTEGER |
<text> | The text sequence to split into n-grams. | TEXT |
Return Types
ARRAY(TEXT)
- If any of the inputs is nullable, the result type is
ARRAY(TEXT) NULL
.
Behavior
The function splits the input text into overlapping contiguous subsequences of lengthn
.
- If
n
is smaller than the size of the input text, an array containing the single value of the input text is returned. - If
n
is smaller than 1, an error is thrown. - If any input is
NULL
, the result isNULL
regardless of the other input value.
Errors
An error is thrown ifn
is smaller than 1.
Respect/Ignore Nulls
Propagates nulls: If any input isNULL
, the result is NULL
.
Examples
The following example generates 2-grams (bigrams) from the string βhello worldβ:result (ARRAY(TEXT)) |
---|
{he,el,ll,lo,"o "," w",wo,or,rl,ld} |
result (ARRAY(TEXT)) |
---|
{hel,ell,llo,"lo ","o w"," wo",wor,orl,rld} |
result (ARRAY(TEXT)) |
---|
{h,e,l,l,o} |
result (ARRAY(TEXT)) |
---|
{hi} |
result (ARRAY(TEXT)) |
---|
{γγ,γγ«,γ«γ‘,γ‘γ―} |
result (ARRAY(TEXT)) |
---|
{ππ,ππ} |