Transformations on Corpora
Interface to apply transformation functions (also denoted as mappings) to corpora.
1 2 3 4
a transformation function taking a text document as input and
returning a text document. The function
a logical. Lazy mappings are mappings which are delayed until the content is accessed. It is useful for large corpora if only few documents will be accessed. In such a case it avoids the computationally expensive application of the mapping to all elements in the corpus.
A corpus with
FUN applied to each document in
x. In case
of lazy mappings only internal flags are set. Access of individual documents
triggers the execution of the corresponding transformation function.
Lazy transformations change R's standard evaluation semantics.
getTransformations for available transformations.
1 2 3 4 5 6 7 8 9 10 11 12
data("crude") ## Document access triggers the stemming function ## (i.e., all other documents are not stemmed yet) tm_map(crude, stemDocument, lazy = TRUE)[] ## Use wrapper to apply character processing function tm_map(crude, content_transformer(tolower)) ## Generate a custom transformation function which takes the heading as new content headings <- function(x) PlainTextDocument(meta(x, "heading"), id = meta(x, "id"), language = meta(x, "language")) inspect(tm_map(crude, headings))
Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.