ScriptSpan#

class scikitplot.corpus.ScriptSpan(text, script, direction, start, end)[source]#

A contiguous span of text in a single Unicode script.

Produced by ScriptSegmenter from NFC-normalised text. All index fields refer to grapheme cluster indices (as produced by regex.findall(r'\X', nfc_text)), not raw codepoint offsets.

Parameters:
textstr

The span text (NFC normalised).

scriptScriptType

Detected script for this span.

directionstr

Writing direction: "ltr" | "rtl" | "ttb".

startint

Grapheme cluster index in the parent document (inclusive).

endint

Grapheme cluster index in the parent document (exclusive).

Parameters:

Notes

Developer note: Grapheme cluster indices (start, end) refer to the regex.findall(r'\\X', nfc_text) list produced by GraphemeClusterNormalizer, not codepoint offsets. A single emoji with ZWJ may span 3+ codepoints but occupies exactly 1 grapheme cluster index slot.

Examples

>>> span = ScriptSpan(
...     text="Hello", script=ScriptType.LATIN, direction="ltr", start=0, end=5
... )
>>> span.script
<ScriptType.LATIN: 'latin'>
direction: str[source]#
end: int[source]#
script: ScriptType[source]#
start: int[source]#
text: str[source]#