Finds all occurrences of all given patterns in the FM Index, analogous to
stringi::stri_locate()
and str_locate()
from stringr
.
Arguments
- patterns
Vector of strings to look for in the index
- index
Index created with
fm_index_create()
Value
A data frame with three columns. pattern_index
is the index
of the query pattern, corpus_index
is the index of the matching
string in the corpus, and position
is the starting position of the
match within the corpus string. All indices are 1-based.
See also
Other FM Index functions:
fm_index_create()
,
fm_index_save()
Examples
data("state")
index <- fm_index_create(state.name, case_sensitive = FALSE)
# Find all states with "new" in their names
hits <- fm_index_locate("new", index)
hits
#> pattern_index corpus_index position
#> 1 1 29 1
#> 2 1 30 1
#> 3 1 31 1
#> 4 1 32 1
# Show matching strings in library
state.name[hits$library_index]
#> character(0)
hits <- fm_index_locate("ar", index)
hits
#> pattern_index corpus_index position
#> 1 1 8 6
#> 2 1 38 12
#> 3 1 3 1
#> 4 1 4 1
#> 5 1 33 8
#> 6 1 40 8
#> 7 1 20 2
state.name[hits$library_index]
#> character(0)