NltkDetector#

class scikitplot.cleanprompt.NltkDetector(labels=frozenset({'EVENT', 'FAC', 'GPE', 'LANGUAGE', 'LAW', 'LOC', 'NORP', 'ORG', 'PERSON', 'PRODUCT', 'WORK_OF_ART'}), language='en', kind_prefix='', priority=None, confidence=None)[source]#

Detect named entities with NLTK’s maximum-entropy chunker.

Parameters:
labelsiterable of str, optional

Canonical labels to keep. None keeps every label reported. Defaults to DEFAULT_ENTITY_LABELS.

languagestr, default=’en’

Language code. Anything but "en" raises, because the chunker is trained on English only.

kind_prefixstr, default=’’

Prepended to the canonical label to form the placeholder category.

priorityint, optional

Arbitration weight. Defaults to the engine’s declared priority, which is below the structural patterns so an address recognised by both is labelled EMAIL rather than ORG.

confidencefloat, optional

Reported confidence. Defaults to the engine’s declared value, which is lower than spaCy’s — a documented judgement about relative quality, not a calibrated probability.

Raises:
CapabilityError

On first detection, if the tier or its corpora are unavailable, or if a language other than English was requested.

Parameters:
  • labels (Iterable[str] | None)

  • language (str)

  • kind_prefix (str)

  • priority (int | None)

  • confidence (float | None)

Examples

>>> detector = NltkDetector()
>>> detector.name
'nltk'
confidence#

!! processed by numpydoc !!

detect(text, policy)[source]#

Yield one span per accepted named entity.

Parameters:
textstr

The original text.

policyRedactionPolicy

The active policy. Unused; present for protocol conformance.

Yields:
Span

Entities whose canonical label is selected, in ascending start order. Every span’s text equals text[start:end].

Raises:
CapabilityError

If the tier, language or corpora are unavailable.

DetectorError

If NLTK raises while processing the text.

Parameters:
Return type:

Iterator[Span]

kind#

!! processed by numpydoc !!

kind_prefix#

!! processed by numpydoc !!

kinds()[source]#

Return the placeholder categories this detector can produce.

Return type:

tuple[str, …]

labels: frozenset[str] | None#

!! processed by numpydoc !!

language#

!! 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.