concordances: concordances

Description Usage Arguments Details Value Examples

View source: R/corpus.R

Description

Print documents which contain one or more terms and return a sub-corpus with these documents.

Usage

1
concordances(corpus, dtm, terms, all = FALSE)

Arguments

corpus

A Corpus object.

dtm

A DocumentTermMatrix object corresponding to corpus.

terms

One of more terms appearing in dtm.

all

Whether only documents containing all terms should be printed. By default, documents need to contain at least one of the terms.

Details

Occurrences of the specified terms are highlighted. If stemming or other transformations have been applied to original words using combine_terms, all original words which have been transformed to the specified terms are highlighted.

Value

Corpus object (invisibly).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
file <- system.file("texts", "reut21578-factiva.xml", package="tm.plugin.factiva")
corpus <- import_corpus(file, "factiva", language="en")
dtm <- build_dtm(corpus)
concordances(corpus, dtm, "oil")
concordances(corpus, dtm, c("oil", "opec"))
concordances(corpus, dtm, c("oil", "opec"), all=TRUE)

# Also works when terms have been combined
dict <- dictionary(dtm)
dtm2 <- combine_terms(dtm, dict)
concordances(corpus, dtm2, "product")

R.temis documentation built on May 13, 2021, 1:08 a.m.