WritingSystemAdapter#
- class scikitplot.corpus.WritingSystemAdapter(config=None, *, extra_strategies=None)[source]#
Dispatch per-script segmentation to the correct strategy.
Receives a list of
ScriptSpanobjects (produced byScriptSegmenter) and routes each span to the matchingSegmentationStrategy.Strategy registry (priority):
Custom strategy registered in
_TOKENIZER_REGISTRYunder the script value string (e.g."japanese","arabic").Built-in strategy for the detected
ScriptType.GraphemeClusterStrategy— unconditional fallback.
- Parameters:
- configWritingSystemAdapterConfig or None, optional
Adapter-level configuration. Default
None→WritingSystemAdapterConfig()(word-level, no max size).- extra_strategiesdict[str, SegmentationStrategy] or None, optional
Additional
{script_value: strategy}mappings that override the built-in registry for this adapter instance only. Useful for testing or domain-specific customisation without touching the global registry.
- Parameters:
config (WritingSystemAdapterConfig | None)
extra_strategies (dict[str, SegmentationStrategy] | None)
Notes
User note: Use
WritingSystemAdapteras theadapterparameter ofSemanticChunker(Layer 3). You can also call it standalone:adapter = WritingSystemAdapter(WritingSystemAdapterConfig(unit="word")) spans = ScriptSegmenter().segment(text) chunks = adapter.adapt(spans)
Developer note (Q3 compliance): Every strategy that cannot load its optional dependency logs a warning and falls back to
GraphemeClusterStrategy. This adapter additionally wraps everystrategy.segment()call in a try/except so a bug in a custom strategy cannot crash the pipeline.Examples
>>> adapter = WritingSystemAdapter() >>> spans = ScriptSegmenter().segment("Hello 世界") >>> chunks = adapter.adapt(spans) >>> [c.text for c in chunks] ['Hello', '世', '界']
- adapt(spans)[source]#
Segment spans using the per-script strategy registry.
- Parameters:
- spanssequence of ScriptSpan
Script spans from
ScriptSegmenter.
- Returns:
- list[Chunk]
Flat, ordered list of all chunks across all spans. Always non-empty for non-empty input.
- Parameters:
spans (Sequence[ScriptSpan])
- Return type: