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.
Nonekeeps every label reported. Defaults toDEFAULT_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
EMAILrather thanORG.- 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:
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
textequalstext[start:end].
- Raises:
- CapabilityError
If the tier, language or corpora are unavailable.
- DetectorError
If NLTK raises while processing the text.
- Parameters:
text (str)
policy (RedactionPolicy)
- Return type:
Iterator[Span]
- kind#
!! processed by numpydoc !!
- kind_prefix#
!! processed by numpydoc !!
- language#
!! processed by numpydoc !!
- name#
!! processed by numpydoc !!
- priority#
!! processed by numpydoc !!
- reads_view = False#
Whether
detectis 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.Falseby 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 todetect.