~/bend-docscommunity

nfc.bend checks

raw source on the hub · import bend-bpe-tokenizer@0.1.0.0/nfc.bend as Nfc

Unicode NFC, as UAX #15 defines it: full canonical decomposition, canonical ordering (a stable sort of each run of combining marks by combining class), then canonical composition (each character joins the last starter unless a mark in between blocks it). Hangul syllables are decomposed and composed by arithmetic; everything else comes from the tables, passed in (tok.bend gives tables.bend's), which hold exactly what Hugging Face's NFC knows.

2 imports
import Base
import ./tree.bend as T

Types

type NT source · line 8 · raw

Data

type CK source · line 52 · raw

Data

---- canonical ordering ----

type RO source · line 88 · raw

Data

type CS source · line 132 · raw

Data

done: finished code points (last first); st: the last starter, if any; between: the marks after it (last first); prev: the class of the last of them (0 for none)

Definitions

def nt_ccc source · line 11 · raw

@nt:NT -> 0x0c46c789483b48a99efa2c996652d510/tree.RT

def nt_dec source · line 16 · raw

@nt:NT -> 0x0c46c789483b48a99efa2c996652d510/tree.KT

def nt_comp source · line 21 · raw

@nt:NT -> 0x0c46c789483b48a99efa2c996652d510/tree.PT

def ccc source · line 26 · raw

@+nt:NT -> @+c:U32 -> U32

def is_syllable source · line 31 · raw

@+c:U32 -> Bool

---- Hangul: syllables are L V (T) jamo sequences, by arithmetic ---- SBase 0xAC00, LBase 0x1100, VBase 0x1161, TBase 0x11A7; 19 L, 21 V, 28 T, 588 = 21 * 28, 11172 syllables

def hangul_t source · line 34 · raw

@+s:U32 -> List<&2, U32>

def hangul source · line 37 · raw

@+s:U32 -> List<&2, U32>

def decompose1 source · line 41 · raw

@+nt:NT -> @+c:U32 -> List<&2, U32>

---- decomposition ----

def decompose source · line 44 · raw

@+nt:NT -> @cs:List<&2, U32> -> List<&2, U32>

def ck_k source · line 55 · raw

@x:CK -> U32

def ck_c source · line 60 · raw

@x:CK -> U32

def ins_here source · line 65 · raw

@after:Bool -> @+x:CK -> @+h:CK -> @t:List<&2, CK> -> @rest:(@_:Unit -> List<&2, CK>) -> List<&2, CK>

def ins source · line 73 · raw

@run:List<&2, CK> -> @+x:CK -> List<&2, CK>

x into a run sorted by class, after every element of its class or lower (so equal classes keep their order)

def flush source · line 81 · raw

@run:List<&2, CK> -> @out:List<&2, U32> -> List<&2, U32>

a run, onto out (last first)

def ro_step source · line 91 · raw

@z:Bool -> @+c:U32 -> @+k:U32 -> @run:List<&2, CK> -> @out:List<&2, U32> -> RO

def ro_add source · line 98 · raw

@+nt:NT -> @st:RO -> @+c:U32 -> RO

def reorder_go source · line 103 · raw

@+nt:NT -> @cs:List<&2, U32> -> @st:RO -> RO

def ro_done source · line 110 · raw

@st:RO -> List<&2, U32>

def reorder source · line 115 · raw

@+nt:NT -> @cs:List<&2, U32> -> List<&2, U32>

def in_lv source · line 119 · raw

@+a:U32 -> @+b:U32 -> Bool

---- canonical composition ----

def in_lvt source · line 122 · raw

@+a:U32 -> @+b:U32 -> Bool

def pair source · line 126 · raw

@+nt:NT -> @+a:U32 -> @+b:U32 -> Maybe<&2, U32>

the primary composite of a b, if any

def mlist source · line 135 · raw

@m:Maybe<&2, U32> -> List<&2, U32>

def is_nil source · line 142 · raw

@xs:List<&2, U32> -> Bool

def cs_new source · line 150 · raw

@z:Bool -> @+c:U32 -> @+k:U32 -> @done:List<&2, U32> -> @st:Maybe<&2, U32> -> @between:List<&2, U32> -> @prev:U32 -> CS

c starts a new run (a starter) or joins the marks after the last starter

def cs_comp source · line 157 · raw

@m:Maybe<&2, U32> -> @+s:U32 -> @+c:U32 -> @+k:U32 -> @done:List<&2, U32> -> @between:List<&2, U32> -> @prev:U32 -> CS

def cs_st source · line 164 · raw

@st:Maybe<&2, U32> -> @+nt:NT -> @+c:U32 -> @+k:U32 -> @done:List<&2, U32> -> @+between:List<&2, U32> -> @+prev:U32 -> CS

def cs_add source · line 172 · raw

@+nt:NT -> @s:CS -> @+c:U32 -> CS

def compose_go source · line 177 · raw

@+nt:NT -> @cs:List<&2, U32> -> @s:CS -> CS

def cs_done source · line 184 · raw

@s:CS -> List<&2, U32>

def compose source · line 189 · raw

@+nt:NT -> @cs:List<&2, U32> -> List<&2, U32>

def nfc source · line 192 · raw

@+nt:NT -> @cs:List<&2, U32> -> List<&2, U32>