ComponentRegistry#
- class scikitplot.corpus.ComponentRegistry[source]#
Central look-up table for corpus pipeline components.
Stores class references (not instances) for four component types: chunkers, filters, readers, and normalizers. Callers retrieve a class and instantiate it with their own parameters.
Notes
The module-level
registrysingleton is pre-populated with all built-in components viaregister_builtins. Third-party packages can register additional components after import.Examples
>>> from scikitplot.corpus._registry import registry >>> registry.register_builtins() >>> chunker = registry.build_chunker("paragraph", min_length=20) >>> type(chunker).__name__, chunker.config.min_length ('ParagraphChunker', 20)
- build_chunker(name, **kwargs)[source]#
Instantiate the chunker registered under
name.- Parameters:
- namestr
Registry key.
- **kwargs
For a chunker registered with a config class: the config’s fields, plus any other keyword option the chunker’s constructor takes (
gensim_dictionaryforword,adapterforsemantic); a name that is both goes to the config. Orconfig=(a ready config,Nonefor the default) with only constructor options beside it. Without a config class: the constructor’s keyword arguments.
- Returns:
- object
The chunker instance.
- Raises:
- KeyError
If
nameis not registered.- TypeError
If a keyword is neither a config field nor a constructor option (the message lists both), a field is given beside
config=, orconfig=is not that config type.
- Parameters:
- Return type:
Notes
Developer. Raw keyword arguments used to reach chunkers whose constructor takes only
config=, so every named chunker raisedTypeErrorfor any option (R3-1).Examples
>>> chunker = registry.build_chunker( ... "fixed_window", window_size=50, step_size=25 ... ) >>> chunker.config.window_size, chunker.config.step_size (50, 25)
- classmethod load_from_snapshot(snapshot, *, allowed_module_prefixes='scikitplot.')[source]#
Reconstruct a registry from a snapshot.
- Parameters:
- snapshotdict
Snapshot created by
snapshot().- allowed_module_prefixesstr | list[str] | None, default=”scikitplot.”
If provided, only classes whose module starts with one of these prefixes are allowed. Recommended for security.
Caution
⚠: Loading arbitrary FQCN from untrusted JSON is remote code execution risk.
- Returns:
- ComponentRegistry
New registry populated from snapshot.
- Raises:
- ValueError
If snapshot structure is invalid.
- TypeError
If resolved class does not match expected base type.
- Parameters:
- Return type:
- register_builtins()[source]#
Register all built-in corpus pipeline components.
Safe to call multiple times — subsequent calls are no-ops. Triggers the necessary imports to populate the
DocumentReaderregistry as well.Notes
Importing
scikitplot.corpus._readersas a side effect here is intentional: it populates theDocumentReader._registryextension map used bycreate.A name already registered is kept: a component you registered before this call is never replaced by the built-in of the same name (the builder calls this on the shared registry when a build starts).
- Return type:
None
- register_chunker(name, cls, *, config=None, replace=False)[source]#
Register a chunker class under
name.- Parameters:
- namestr
Registry key (lowercase, underscore-separated). Must be non-empty.
- clstype
A class satisfying
ChunkerProtocol(chunkandchunk_batch).- configtype or None, optional
The chunker’s configuration dataclass. When given (or declared by the class as
config_class, as every built-in does),build_chunker(andBuilderConfig.chunker_kwargs) build this config from keyword arguments and pass it ascls(config=...); unknown keys raise. When neither, keyword arguments go toclsdirectly. A class declaringconfig_classaccepts only that class or a subclass.- replacebool, optional
Replace an existing registration deliberately. Default
False.
- Raises:
- ValueError
If
nameis empty, or already registered andreplaceisFalse.- TypeError
If
clsis not a conforming class, itschunkcannot takeextra_metadata, orconfigis not a dataclass type (or not the class’s declaredconfig_class).
- Parameters:
- Return type:
None
- register_filter(name, cls, *, replace=False)[source]#
Register a filter class under
name.- Parameters:
- namestr
- clstype
Concrete class inheriting from
FilterBase.
- Parameters:
- Return type:
None
- register_normalizer(name, cls, *, replace=False)[source]#
Register a normalizer class under
name.- Parameters:
- namestr
a normalizer class.
- clstype
Concrete class inheriting from
NormalizerBase.- replacebool
False
- Parameters:
- Return type:
None
Notes
Developer. Checked against
NormalizerBase, the typeNormalizationPipelineaccepts.NormalizerProtocol(normalize(text)) describes a text-level interface no built-in normalizer has, so the old check refused every built-in, and with it every snapshot round trip (R3-1).
- register_reader(name, cls, *, replace=False)[source]#
Register a reader class under
name(typically a file extension).- Parameters:
- namestr
File extension (e.g.
\".txt\") or URL scheme key (e.g.\":url\").- clstype
Concrete class inheriting from
DocumentReader.- replacebool
False
- Parameters:
- Return type:
None