text_sub: Text Subsequences

Description Usage Arguments Details Value See Also Examples

View source: R/token.R

Description

Extract token subsequences from a set of texts.

Usage

1
text_sub(x, start = 1L, end = -1L, filter = NULL, ...)

Arguments

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 start is a two-column matrix.

filter

if non-NULL, a text filter to to use instead of the default text filter for x.

...

additional properties to set on the text filter.

Details

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.

Value

A text vector with the same length and names as x, with the desired subsequences.

See Also

text_tokens, text_ntoken.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
x <- as_corpus_text(c("A man, a plan.", "A \"canal\"?", "Panama!"),
                    drop_punct = TRUE)

# entire text
text_sub(x, 1, -1)

# first three elements
text_sub(x, 1, 3)

# last two elements
text_sub(x, -2, -1)

corpus documentation built on May 2, 2021, 9:06 a.m.