Extract token subsequences from a set of texts.
text_sub(x, start = 1L, end = -1L, filter = NULL, ...)
x | text vector or corpus object. |
---|---|
start | integer vector giving the starting positions of the subsequences, or a two-column integer matrix giving the starting and ending positions. |
end | integer vector giving the ending positions of the
subsequences; ignored if |
filter | if non- |
… | additional properties to set on the text filter. |
text_sub
extracts token subsequences from a set of texts.
The start
and end
arguments specifying the
positions of the subsequences within the parent texts, as an inclusive
range. Negative indices are interpreted as counting from the end of
the text, with -1L
referring to the last element.
A text vector with the same length and names as x
, with the
desired subsequences.
x <- as_corpus_text(c("A man, a plan.", "A \"canal\"?", "Panama!"), drop_punct = TRUE) # entire text text_sub(x, 1, -1)#> [1] "A man, a plan." "A \"canal\"?" "Panama!"# first three elements text_sub(x, 1, 3)#> [1] "A man, a " "A \"canal\"?" "Panama!"# last two elements text_sub(x, -2, -1)#> [1] "a plan." "A \"canal\"?" "Panama!"