File: ngrams.Rd

package info (click to toggle)
r-cran-nlp 0.1-9-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 376 kB
  • sloc: makefile: 1
file content (24 lines) | stat: -rw-r--r-- 604 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
\name{ngrams}
\alias{ngrams}
\title{Compute N-Grams}
\description{
  Compute the \eqn{n}-grams (contiguous sub-sequences of length \eqn{n})
  of a given sequence.
}
\arguments{
  \item{x}{a sequence (vector).}
  \item{n}{a positive integer giving the length of contiguous
    sub-sequences to be computed}
}
\value{
  a list with the computed sub-sequences.
}
\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)
## Word tri-grams pasted together:
vapply(ngrams(w, 3L), paste, "", collapse = " ")
}