ScriptSpan#
- class scikitplot.corpus.ScriptSpan(text, script, direction, start, end)[source]#
A contiguous span of text in a single Unicode script.
Produced by
ScriptSegmenterfrom NFC-normalised text. All index fields refer to grapheme cluster indices (as produced byregex.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:
text (str)
script (ScriptType)
direction (str)
start (int)
end (int)
Notes
Developer note: Grapheme cluster indices (start, end) refer to the
regex.findall(r'\\X', nfc_text)list produced byGraphemeClusterNormalizer, 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'>
- script: ScriptType[source]#