metric_contains() makes a metric that is TRUE when the prediction
contains pattern. The pattern is fixed when you create the metric: the
metric ignores its expected argument, so every row is checked for the
same pattern. To compare against a column of the data, use
metric_exact_match(), metric_f1() or a custom metric.
Value
A function function(prediction, expected = NULL) returning
TRUE or FALSE. field is stored in its "field" attribute.
Examples
cites_source <- metric_contains("[source]", field = "answer")
cites_source(list(answer = "Paris [source]"))
#> [1] TRUE
cites_source(list(answer = "Paris"))
#> [1] FALSE
# The expected value is ignored
cites_source(list(answer = "Paris [source]"), data.frame(answer = "Lyon"))
#> [1] TRUE
# A regular expression
has_number <- metric_contains("[0-9]+", field = "answer", fixed = FALSE)
has_number(list(answer = "The answer is 42"))
#> [1] TRUE