Detector#

class scikitplot.cleanprompt.Detector(name, kind, priority=50, confidence=1.0)[source]#

Base class for detectors.

Subclasses implement detect. The base class supplies the identity attributes and the error wrapping used by DetectorRegistry.detect_all.

Parameters:
namestr

Unique, stable identifier. Used in arbitration tie-breaks, so it must not change between runs.

kindstr

Category assigned to every span this detector produces.

priorityint, default=50

Arbitration weight.

confidencefloat, default=1.0

Confidence reported for every span.

Raises:
PolicyError

If name or kind is empty, or confidence is out of range.

Parameters:
confidence#

!! processed by numpydoc !!

detect(text, policy)[source]#

Yield spans over text.

Parameters:
textstr

The original text. Never a rewritten one.

policyRedactionPolicy

The active policy.

Yields:
Span

One per match, in ascending start order.

Raises:
NotImplementedError

Always, on the base class.

Parameters:
Return type:

Iterable[Span]

kind#

!! processed by numpydoc !!

name#

!! processed by numpydoc !!

priority#

!! processed by numpydoc !!

reads_view = False#

Whether detect is a pure function of the text it is given, so that it may also read the detection view (CP-098) and have its spans mapped back onto the original. False by default: a detector bound to one document — offsets computed in advance from the original, such as a field or region detector — would have its spans mapped twice and cut through a file’s structure (CP-102). Opt in only when every offset a detector yields indexes the string passed to detect.