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 character highlight(.Object, highlight = list(), regex = FALSE, perl = FALSE, ...) # S4 method for html highlight(.Object, highlight = list(), regex = FALSE, perl = FALSE, ...) # S4 method for kwic highlight( .Object, highlight = list(), regex = FALSE, perl = TRUE, verbose = TRUE, ... )
.Object | A |
---|---|
... | Terms to be highlighted can be passed in as named character vectors of terms (or regular expressions); the name then needs to be a valid color name. |
highlight | A character vector, or a list of character or integer vectors. |
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.
#>#>#>#>H <- html(P) Y <- highlight(H, list(lightgreen = "higher")) if (interactive()) htmltools::html_print(Y) # highlight matches for a CQP query H2 <- highlight( H, highlight = list(yellow = cpos(hits(P, query = '"prod.*"', cqp = TRUE))) ) # 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 )