basic-tokenizers | R Documentation |
These functions perform basic tokenization into words, sentences, paragraphs, lines, and characters. The functions can be piped into one another to create at most two levels of tokenization. For instance, one might split a text into paragraphs and then word tokens, or into sentences and then word tokens.
tokenize_characters(
x,
lowercase = TRUE,
strip_non_alphanum = TRUE,
simplify = FALSE
)
tokenize_words(
x,
lowercase = TRUE,
stopwords = NULL,
strip_punct = TRUE,
strip_numeric = FALSE,
simplify = FALSE
)
tokenize_sentences(x, lowercase = FALSE, strip_punct = FALSE, simplify = FALSE)
tokenize_lines(x, simplify = FALSE)
tokenize_paragraphs(x, paragraph_break = "\n\n", simplify = FALSE)
tokenize_regex(x, pattern = "\\s+", simplify = FALSE)
x |
A character vector or a list of character vectors to be tokenized.
If |
lowercase |
Should the tokens be made lower case? The default value
varies by tokenizer; it is only |
strip_non_alphanum |
Should punctuation and white space be stripped? |
simplify |
|
stopwords |
A character vector of stop words to be excluded. |
strip_punct |
Should punctuation be stripped? |
strip_numeric |
Should numbers be stripped? |
paragraph_break |
A string identifying the boundary between two paragraphs. |
pattern |
A regular expression that defines the split. |
A list of character vectors containing the tokens, with one element
in the list for each element that was passed as input. If simplify =
TRUE
and only a single element was passed as input, then the output is a
character vector of tokens.
song <- paste0("How many roads must a man walk down\n",
"Before you call him a man?\n",
"How many seas must a white dove sail\n",
"Before she sleeps in the sand?\n",
"\n",
"How many times must the cannonballs fly\n",
"Before they're forever banned?\n",
"The answer, my friend, is blowin' in the wind.\n",
"The answer is blowin' in the wind.\n")
tokenize_words(song)
tokenize_words(song, strip_punct = FALSE)
tokenize_sentences(song)
tokenize_paragraphs(song)
tokenize_lines(song)
tokenize_characters(song)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.