LiteralDetector#
- class scikitplot.cleanprompt.LiteralDetector(terms, kind='CUSTOM', name=None, priority=75, word_boundary=False, ignore_case=False)[source]#
Detector for exact strings the caller names.
- Parameters:
- termsiterable of str
Strings to hide. Empty and whitespace-only terms are rejected.
- kindstr, default=’CUSTOM’
Category for every match.
- namestr, optional
Detector name. Defaults to
"literal:<kind>".- priorityint, default=75
Arbitration weight. Above the structural patterns by default, because a caller naming a term explicitly has expressed stronger intent than a generic pattern.
- word_boundarybool, default=False
When
True, a term matches only at word boundaries.- ignore_casebool, default=False
When
True, terms match regardless of case. Normally supplied fromcase_insensitiveso that one setting governs both halves of “case is not significant”: which surfaces match, and which surfaces share a label. Implementing only the second half would silently ignore--hide acmeagainst the textAcme.
- Raises:
- PolicyError
If a term is empty or whitespace-only.
- Parameters:
Notes
User notes. This is the “additional words to hide” feature. Terms are matched literally, not as regular expressions, so
a.bmatches exactlya.band notaxb.Developer notes. Two properties matter here, and both were absent upstream.
Longest-first alternation. Terms are sorted by descending length inside one alternation, so scanning
"Ann met Anna"for["Ann", "Anna"]matchesAnnaat its position rather thanAnnfollowed by a strandeda. Upstream rewrote the string once per term withstr.replaceand produced"[ADDITIONAL-1] met [ADDITIONAL-1]a"— defectCP-001, which both corrupts the text and leaks the finalaof the secret.One pass. All terms are scanned in a single alternation, so cost is linear in the text rather than linear in
len(text) * len(terms).Examples
>>> from ._policy import DEFAULT_POLICY >>> detector = LiteralDetector(["Ann", "Anna"]) >>> [(s.start, s.text) for s in detector.detect("Ann met Anna", DEFAULT_POLICY)] [(0, 'Ann'), (8, 'Anna')]
- confidence#
!! processed by numpydoc !!
- detect(text, policy)[source]#
Yield one span per literal occurrence.
- Parameters:
- textstr
The original text.
- policyRedactionPolicy
The active policy. Unused; present for protocol conformance.
- Yields:
- Span
Matches in ascending start order, longest alternative first at any given position.
- Parameters:
text (str)
policy (RedactionPolicy)
- Return type:
Iterator[Span]
- ignore_case#
!! processed by numpydoc !!
- kind#
!! processed by numpydoc !!
- name#
!! processed by numpydoc !!
- priority#
!! processed by numpydoc !!
- reads_view = True#
may read the detection view.
- Type:
Offsets index the text given to
detect
- word_boundary#
!! processed by numpydoc !!