File: ngrams.Rd

package info (click to toggle)
r-cran-nlp 0.3-2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 456 kB
  • sloc: makefile: 2
file content (24 lines) | stat: -rw-r--r-- 605 bytes parent folder | download | duplicates (3)
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 = " ")
}