Skip to contents

Runs every registered detector over normalised text, validates candidates (checksums, code tables), scores them from nearby context and resolves overlapping matches (the more confident, then the longer, span wins - so a GSTIN is reported once, not also as the PAN inside it).

Usage

detect_pii(
  text,
  detectors = NULL,
  context = NULL,
  min_confidence = 0,
  window = NULL
)

Arguments

text

A character vector.

detectors

Detector ids to run; NULL runs all registered detectors (see cg_detectors()).

context

Optional extra context per element of text (recycled), treated as if it appeared next to every match. scan_pii() (planned) passes column names here, so a column called voter_id supports Voter ID matches.

min_confidence

Drop matches scoring below this value.

window

Number of characters either side of a match searched for context keywords; NULL uses the spec's context_window.

Value

A data frame of class cg_spans with one row per match: doc (index into text), start, end (character positions in the original text), type, class, value, canonical, confidence and reasons. Printing masks the values.

Examples

detect_pii("Customer PAN ABCPE1234F, GSTIN 27AAPFU0939F1ZV")
#> 2 PII matches (values masked; use `x$value` to see them):
#>  doc start end  type           value confidence
#>    1    14  23   pan      XXXXXX234F       0.97
#>    1    32  46 gstin XXXXXXXXXXXF1ZV       0.99