build_detectors#

scikitplot.cleanprompt.build_detectors(mode='auto', language='en', model=None, labels=frozenset({'EVENT', 'FAC', 'GPE', 'LANGUAGE', 'LAW', 'LOC', 'NORP', 'ORG', 'PERSON', 'PRODUCT', 'WORK_OF_ART'}), size='sm', required=False)[source]#

Construct the detectors for an engine mode.

Parameters:
modestr, default=’auto’

One of ENGINE_MODES.

languagestr, default=’en’

Language code.

modelstr, optional

Explicit spaCy model name, overriding language-based resolution.

labelsfrozenset of str, optional

Canonical labels to redact. None redacts every label reported.

sizestr, default=’sm’

Preferred spaCy model size.

requiredbool, default=False

Whether the caller explicitly asked for entity detection. When true, every engine that will run must be ready, data included, or this raises. See the notes.

Returns:
list of Detector

Constructed detectors, in engine priority order. Construction loads no model: each detector loads its engine on first use.

Raises:
PolicyError

If mode is unknown.

CapabilityError

If required is true and the request cannot be met: auto found no ready engine, or a named engine (or either of both) is not ready. mode="none" is exempt: it is an explicit instruction to run no engine.

Parameters:
Return type:

list[Detector]

Notes

Developer notes. Without required nothing here imports spaCy or NLTK, which is what keeps --help free of a multi-second load. With required NLTK may be imported to check its data — only when NLTK is about to run, so the import is paid once and early rather than once and late.

Why ``required`` exists. auto degrades by design: it is the default, and a default that refused to run on a base installation would make the base tier unusable. But --ner is not a default, it is a request. With auto resolving to nothing, honouring that request by adding no detector and exiting successfully tells a user their text was scanned for names when nothing looked (CP-024). And a request for an engine that is installed but has no data must fail here, with the remedy, not at the first sentence — otherwise doctor, which builds through this function too, calls the configuration healthy (CP-093).

This lives here rather than in each caller because there are four callers (the command line, encode, the file runtime and the web app) and a fifth would make the same omission. The web app built its own spaCy detector until CP-094 and ignored the engine, language and model size it was given.