| name | tokenizers |
| description | R tokenizers package for text tokenization. Use for fast, consistent tokenization of text. |
tokenizers
Fast, consistent tokenization of natural language text.
Word Tokenization
library(tokenizers)
tokenize_words("This is a test sentence.")
texts <- c("First sentence.", "Second sentence.")
tokenize_words(texts)
Options
tokenize_words(text, lowercase = TRUE)
tokenize_words(text, strip_punct = FALSE)
tokenize_words(text, strip_numeric = FALSE)
tokenize_words(text, stopwords = stopwords::stopwords("en"))
Sentence Tokenization
tokenize_sentences("First sentence. Second sentence!")
tokenize_sentences(text, strip_punct = FALSE)
Character Tokenization
tokenize_characters("hello")
tokenize_character_shingles("hello", n = 3)
N-grams
tokenize_ngrams("This is a test", n = 2)
tokenize_ngrams("This is a test", n = 2, n_min = 1)
tokenize_skip_ngrams("This is a test", n = 2, k = 1)
Paragraph Tokenization
text <- "First paragraph.\n\nSecond paragraph."
tokenize_paragraphs(text)
Line Tokenization
tokenize_lines("Line 1\nLine 2\nLine 3")
Regex Tokenization
tokenize_regex(text, pattern = "\\s+")
Word Stems
tokenize_word_stems("running cats jumping")
tokenize_word_stems(text, language = "english")
PTB Tokenization
tokenize_ptb("It's a test.")
Tweet Tokenization
tokenize_tweets("Hello @user! Check out #rstats http://example.com")
Count Tokens
count_words("This is a test sentence.")
count_sentences("First. Second. Third.")
count_characters("hello")