ac_count() returns the number of pattern matches in each document.
Usage
ac_count(ac, doc, overlapping = FALSE, na = c("keep", "zero", "error"))Arguments
- ac
An
<ac_automaton>object created byac_build().- doc
A character vector of documents to search.
- overlapping
Default is
FALSE. IfTRUE, count overlapping matches. This is only supported whenacwas built withmatch_kind = "standard".- na
How to handle
NAdocuments."keep"returnsNA_integer_(default);"zero"treats missing documents as zero matches;"error"fails.
Examples
if (requireNamespace("dplyr", quietly = TRUE)) {
ac <- ac_build(c("hello", "world"))
docs <- data.frame(doc = c("hello world", "nothing", "world"))
dplyr::mutate(docs, n_matches = ac_count(ac, doc))
}
#> doc n_matches
#> 1 hello world 2
#> 2 nothing 0
#> 3 world 1