Examples for 'NLP::ngrams'


Compute N-Grams

Aliases: ngrams

Keywords:

### ** Examples

s <- "The quick brown fox jumps over the lazy dog"
## Split into words:
w <- strsplit(s, " ", fixed = TRUE)[[1L]]
## Word tri-grams:
ngrams(w, 3L)
[[1]]
[1] "The"   "quick" "brown"

[[2]]
[1] "quick" "brown" "fox"  

[[3]]
[1] "brown" "fox"   "jumps"

[[4]]
[1] "fox"   "jumps" "over" 

[[5]]
[1] "jumps" "over"  "the"  

[[6]]
[1] "over" "the"  "lazy"

[[7]]
[1] "the"  "lazy" "dog" 
## Word tri-grams pasted together:
vapply(ngrams(w, 3L), paste, "", collapse = " ")
[1] "The quick brown" "quick brown fox" "brown fox jumps" "fox jumps over" 
[5] "jumps over the"  "over the lazy"   "the lazy dog"   

[Package NLP version 0.3-2 Index]