highlight-method | R Documentation |
Highlight tokens in fulltext based on exact match, a regular expression or
corpus position in kwic
output or html
document.
highlight(.Object, ...)
## S4 method for signature 'character'
highlight(.Object, highlight = list(), regex = FALSE, perl = FALSE, ...)
## S4 method for signature 'html'
highlight(.Object, highlight = list(), regex = FALSE, perl = FALSE, ...)
## S4 method for signature 'kwic'
highlight(
.Object,
highlight = list(),
regex = FALSE,
perl = TRUE,
verbose = TRUE,
...
)
.Object |
A |
... |
Terms to be highlighted can be passed in as named |
highlight |
A character vector, or a list of |
regex |
Logical, whether character vectors are interpreted as regular expressions. |
perl |
Logical, whether to use perl-style regular expressions for
highlighting when regex is |
verbose |
Logical, whether to output messages. |
If highlight
is a character vector, the names of the vector are interpreted
as colors. If highlight
is a list, the names of the list are considered as
colors. Values can be character values or integer values with token ids.
Colors are inserted into the output html and need to be digestable for the
browser used.
use("polmineR")
use(pkg = "RcppCWB", corpus = "REUTERS")
P <- partition("REUTERS", places = "argentina")
H <- html(P)
Y <- highlight(H, list(lightgreen = "higher"))
if (interactive()) htmltools::html_print(Y)
# highlight matches for a CQP query
regions <- cpos(P, query = '"prod.*"', cqp = TRUE)
H2 <- highlight(H, highlight = list(yellow = regions))
# the method can be used in pipe
P %>% html() %>% highlight(list(lightgreen = "1986")) -> H
P %>% html() %>% highlight(list(lightgreen = c("1986", "higher"))) -> H
P %>% html() %>% highlight(list(lightgreen = 4020:4023)) -> H
# use highlight for kwic output
K <- kwic("REUTERS", query = "barrel")
K2 <- highlight(K, highlight = list(yellow = c("oil", "price")))
# use character vector for output, not list
K2 <- highlight(
K,
highlight = c(
green = "pric.",
red = "reduction",
red = "decrease",
orange = "dropped"
),
regex = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.